Remove lines efficiently in Vim

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

Léo Léopold Hertz 준영

Posted 2009-08-20T23:08:51.750

Reputation: 4 828

All I know is that I use the 'dd' command to remove a line – Joe Phillips – 2009-08-20T23:10:48.097

Answers

7

To remove all lines that match div

:g/div/d

To remove all lines that don't match div

:g!/div/d

Steve Losh

Posted 2009-08-20T23:08:51.750

Reputation: 186

6

:g!/div/d

Works just fine to do what you want.

Mark

Posted 2009-08-20T23:08:51.750

Reputation: 226

2Vim 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. – None – 2009-08-20T23:27:25.007

2@thr4wn: superuser isn't the site for servers, that's serverfault. – John Millikin – 2009-08-20T23:28:22.680

1

:V/div/d

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

:%!grep div

user7385

Posted 2009-08-20T23:08:51.750

Reputation: