Advanced Vim Search

Is there a way to search multiple lines at once in Vim? I remember reading somewhere that this is possible, but somehow forgot the technique.

So, for example, I have a text file, and I want to search for "foo" and "bar" at the same time (not necessarily as one line, maybe in different lines in general).

How do I achieve this?

+7
vim search vi
source share
4 answers
/^joe.*fred.*bill/ : find joe AND fred AND Bill (Joe at start of line) /fred\|joe : Search for FRED OR JOE 
+15
source share

In fact, I found the answer shortly after I posted it (yes, I used to do google but couldn't find it. Maybe it was just looking for an error)

The right decision

/ (Foo \ | bar)

@Paul Betts: The pipe must be shielded

+2
source share

Vim supports regular expressions, starting from command mode with '/'.

So using something like "/ (foo \ | bar)" (as mentioned earlier) will solve the problem. It's good to know why this works and what you use (regular expressions).

0
source share
 /(foo|bar) 
-3
source share

All Articles