Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In vim I can delete all lines that contain the word "price" with this

:g /price/d

How can I delete all lines that do NOT contain the word "price"?

share|improve this question
    
Can this question be migrated to vi.stackexchange.com? I tried to flag it for migration but couldn't figure it out. – Mu Mind Dec 21 '15 at 16:40
up vote 39 down vote accepted

You can use

:%g!/price/d

to delete every line that doesn't contain "price"

share|improve this answer
1  
I knew it would be easy... – digitaljoel Mar 31 '11 at 23:28
11  
:g! is also known as :v (akin to grep -v). – Chris Johnsen Apr 1 '11 at 3:17
1  
What does the % do? – hippietrail Oct 30 '12 at 7:05
1  
% is a special range in this context that means the whole file. See :help cmdline-ranges. – Heptite Oct 30 '12 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.