Dark mode switch icon Light mode switch icon

Deleting Lines And Non Matching Lines With Vim

1 min read

I’m always forgetting how to do this but here’s how to delete matching lines:

:g/.*foo.*/d

And the more difficult thing to do that vim makes easy is deleting non-matching lines.  All you do is negate the pattern:

:g!/.*foo.*/d

Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Delete Lines Matching Keyword

Originally published on by Jason Axley