Deleting Lines And Non Matching Lines With Vim
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