In Vim I often find I'm only interested in lines containing a certain string of text and want to delete all other lines.
It's easy to match lines containing a string:
:s/^.*foo.*\n//
What I normally end up doing is two passes, one to "flag" all the lines I want with a special first character:
:s/^\(.*foo.*\)$/X\1/
And in the second pass it's easy to do a negative match for one character in a fixed position, so I delete all the lines without my string thus:
:s/^[^X].*\n//
But isn't there a much more straightforward way to do this with just a single pass? What am I missing?