Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

How can you remove given lines efficiently in Vim?

I want to remove all lines which match this


I unsuccessfully ran:

share|improve this question

migrated from 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
up vote 7 down vote accepted

To remove all lines that match div


To remove all lines that don't match div

share|improve this answer

Works just fine to do what you want.

share|improve this answer
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
@thr4wn: superuser isn't the site for servers, that's serverfault. – John Millikin Aug 20 '09 at 23:28

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

:%!grep div
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .