Reputation: 431
In vim, how can I search for any line that does not end with (in this instance) the word "DROP"?
Upvotes: 16
Views: 4021
Reputation: 59101
/\(DROP\)\@<!$
This uses a zero-width negative look-behind assertion. It finds just the line ending, and only finds line endings that don't have DROP
immediately preceding them.
If you want to find the whole line, you can use:
/^.*\(DROP\)\@<!$
Note that you have to surround DROP
with \( .. \)
because look-ahead and look-behind assertions will only match a single "atom". So you use the parens to group your word into a single atom.
If you tried /DROP\@<!$
, then you'd get search results like the bold part here:
abcdef
test test DRO
12345DROP
12345DRO
12345
There's a tutorial for these assertions on this page, though it doesn't use VIM regex syntax:
You can also type this in VIM to get help on the command:
:help \@<!
Similar assertions:
\@=
\@<=
\@!
Upvotes: 25