2

I'm looking for a quick command in VI(M) where I can delete all text starting from the end of the line to a character. I can do the reverse:

:%s/.*" 

But I want the opposite. I tried:

:%s/$.*" 

but that didn't work (my logic was $ - start from the end of the line, find everything up to " and delete it.

Here is a sample of the text I'm trying to manipulate (EDIT: but this line occurs multiple times - the solution must work for many lines of a similar construction - single line solutions won't be sufficient - apologies for not being clear first):

APPPOOL "default app pool" (some long list of stuff, more entries here) 

becomes

APPPOOL "default app pool" 
1
  • Isn't it the same as deleting from a given character to the end of the line, which you should be able to do with ctrl+d? Or is this going into a script of some sort? Commented Jan 28, 2013 at 17:47

2 Answers 2

11

why not just simply type $dT"?

if you really want to do it with :s, try

:s/"[^"]*$/"/ 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this was it except I added a % before the s.
2

Two thoughts. First:

:s/\(.*"\).*/\1/ 

Or, go to the end of the line and do:

dT"x 

To operate on the whole buffer:

:%normal $dT"x 

3 Comments

Not quite right - that will delete the quote itself. And it also will delete from the first quote, not the last. Maybe :%s/"[^"]\+/"/g
+1 for dT"; the backref in the :s shouldn't be needed though. For example, non-greedy (:s/"\zs.{-}) or character set (:s/"\zs[^"]*).
I tried these too but they didn't work as expected. Kent's solution worked for my needs because it search all lines and deleted the correct text from each lines. the final solution for me was :%s/"[^"]*$/"/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.