How to delete all lines that do NOT contain a certain word in Vim?
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
You can also use:
:v/price/d
to delete lines.
%!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