Delete lines with a pattern in vim2019-04-27
In vim, I know you can search and replace text with
to replace all occurrences in a line after pressing Ctrl-v.
But then, I recently wanted to delete all lines containing a certain pattern and wondered if vim could do this. Turns out. It can.
Below is the pattern to delete lines with a certain pattern.
/d indicates we’re deleting lines and leading
g stands for “global” in
order to affect the entire buffer.
The use case I wanted was to delete lines that started with the number zero. We can also use these commands1 to do more complex search and delete.
You can read more
or by pressing
:help :g (global changes) and
:help :d (delete lines).
Apparently, these are called Ex commands. Maybe I’ll cover these in another post. ↩