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.

How can you remove given lines efficiently in Vim?

I want to remove all lines which match this

:g!/div/

I unsuccessfully ran:

:g!/div/s/^*//g
share|improve this question

migrated from stackoverflow.com Aug 21 '09 at 0:06

This question came from our site for professional and enthusiast programmers.

    
All I know is that I use the 'dd' command to remove a line –  Joe Philllips Aug 20 '09 at 23:10
    
Thank you for your answers! –  Masi Aug 21 '09 at 3:35

3 Answers 3

up vote 7 down vote accepted

To remove all lines that match div

:g/div/d

To remove all lines that don't match div

:g!/div/d
share|improve this answer
:g!/div/d

Works just fine to do what you want.

share|improve this answer
2  
Vim certainly isn't only used on servers. Potentially anyone who does any programming could benefit from this question. I certainly did, and I'm not affiliated at all with servers in my work. –  Thr4wn Aug 20 '09 at 23:27
2  
@thr4wn: superuser isn't the site for servers, that's serverfault. –  John Millikin Aug 20 '09 at 23:28
:V/div/d

In case of larger files, it might be faster to:

:%!grep div
share|improve this answer

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.