Wednesday, August 26, 2009

vim: keep or delete lines matching a pattern

This is similar to a grep on the local buffer. To delete all lines matching a certain regular expression pattern, use
:g/pattern/d
To do the opposite, i.e. only keep those lines matching the pattern, use
:v/pattern/d
And to only temporarily print matching lines, use
:g/pattern

1 comment:

Anonymous said...

If you want to strip out string OR string1 OR string2 etc, it'll look something like:

:v/error\|warn\|fail/d