Mike J
Mike J

Reputation: 1240

VIM delete from end of line to character?

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"

Upvotes: 2

Views: 3541

Answers (2)

William Pursell
William Pursell

Reputation: 212564

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

Upvotes: 2

Kent
Kent

Reputation: 195229

why not just simply type $dT"?

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

:s/"[^"]*$/"/

Upvotes: 11

Related Questions