Categories
Posts

Vim Tip: Delete All Lines That Match A Pattern

The basic approach to deleting all lines that match a pattern in Vim is very simple:

[sourcecode]
:g/[pattern]/d
[/sourcecode]

If you want to do more, you can switch modes. Here is how you would delete all the lines matching a pattern, along with the line below each match:

[sourcecode]
:g/[pattern]/normal 2dd
[/sourcecode]

Leave a Reply

Your email address will not be published. Required fields are marked *