Wikia

Vim Tips Wiki

Search for lines not containing pattern

Talk0
1,613pages on
this wiki

Revision as of 23:20, April 30, 2011 by 72.83.95.249 (Talk)

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1180 Printable Monobook Previous Next

created March 21, 2006 · complexity basic · author Bertram Scharpf · version 6.0


When examining a long log file, you might want to find lines not containing a word. For lines not containing "Warning", the search command is:

/^\(.*Warning\)\@!.*$

or

/\v^(.*Warning)@!.*$

Comments

You might want to add a little note on matching, as the manual states..."Using "\@!" is tricky, because there are many places where a pattern does not match".


If you want to see all such lines at once, there's the traditional (but simple):

:v/Warning/p

A neat trick when working with a large log file where you want to filter out as many irrelevant lines as possible before you get started on your real search is:

:sav junk.log

Now you are editing a clone of your original file and can mess about at will. For example, the following will delete all lines that do not contain the text "warning":

:v/warning/d

Around Wikia's network

Random Wiki