Vim: Delete every line in the file that does not match a pattern
Here is a great tip that covers the virtues of :g in vim:
Tip #227: Power of :g
The reason I ended up with this tip was that I needed to find a simple command that would delete all lines matching a pattern.
I knew how to delete all lines that matched a pattern.
but I was looking for the inverse and I found it :g's cousin :v in the above tip as a user comment.
did the job very well. Once again vim saved the day. :-)