0

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
1
  • All I know is that I use the 'dd' command to remove a line Aug 20, 2009 at 23:10

3 Answers 3

7

To remove all lines that match div

:g/div/d

To remove all lines that don't match div

:g!/div/d
6
:g!/div/d

Works just fine to do what you want.

2
  • 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, 2009 at 23:27
  • 2
    @thr4wn: superuser isn't the site for servers, that's serverfault. Aug 20, 2009 at 23:28
1
:V/div/d

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

:%!grep div

You must log in to answer this question.

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