Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 19 down vote accepted

You can use

:%g!/price/d

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

share|improve this answer
    
I knew it would be easy... –  digitaljoel Mar 31 '11 at 23:28
6  
:g! is also known as :v (akin to grep -v). –  Chris Johnsen Apr 1 '11 at 3:17
    
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.