Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advanced searching in Vim

Tags:

vim

vi

search

Is there a way to search for multiple strings simultaneously in Vim? I recall reading somewhere that it was possible but somehow forgot the technique.

So for example, I have a text file and I want to search for "foo" and "bar" simultaneously (not necessarily as a single string, can be in different lines altogether).

How do I achieve that?

like image 584
AJ. Avatar asked Sep 25 '08 05:09

AJ.


People also ask

How do I search a full word in Vim?

Finding a whole word Simply move the cursor anywhere within the word, then press * to search for the next occurrence of that whole word. Vim inserts \< and \> automatically (see searching). The pattern \<i finds all words that start with "i", while i\> finds all words that end with "i".

How do I find special characters in Vim?

^ * $ \ ? ) have special significance to the search process and must be “escaped” when they are used in a search. To escape a special character, precede it with a backslash ( \ ). For example, to search for the string “anything?” type /anything\? and press Return.


2 Answers

/^joe.*fred.*bill/          : find joe AND fred AND Bill (Joe at start of line)
/fred\|joe                  : Search for FRED OR JOE
like image 66
Codeslayer Avatar answered Oct 13 '22 23:10

Codeslayer


Actually I found the answer soon after I posted this (yes I did google earlier but was unable to locate it. Probably was just searching wrong)

The right solution is

/(foo\|bar)

@Paul Betts: The pipe has to be escaped

like image 24
AJ. Avatar answered Oct 13 '22 23:10

AJ.