In vim I can delete all lines that contain the word "price" with this
:g /price/d
How can I delete all lines that do NOT contain the word "price"?
In vim I can delete all lines that contain the word "price" with this
:g /price/d
How can I delete all lines that do NOT contain the word "price"?
You can use
:g!/price/d
to delete every line that doesn't contain "price"
As answered below, g! is an alias to v. this is equivalent to
:v/price/d
%!grep "price"
is another option that can be considerably faster than :v for large files.
Tested on Vim 7.4, Ubuntu 14.04, 1M line log file.
Lines that contain word: https://stackoverflow.com/questions/1725265/how-can-i-delete-all-lines-that-do-not-begin-with-certain-characters/42714334#42714334