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"?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityYou 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
%
is a special range in this context that means the whole file. See :help cmdline-ranges
.
You can also use:
:v/price/d
to delete lines.
g
is for "global" and v
for "inverse" (if you believe what you read on vim.famdom).
%!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