Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search for 3 strings at a time in the vi editor?

Tags:

linux

vi

unix

How can I search for 3 strings at a time in the vi editor?

I was wondering how could we do it. I.e. search for 3 strings at a time in vi like I do: :/xyz in command mode.

How could I add 2 more strings so that the cursor will stop at a string which ever is found first among the three and if we press n it will stop at the string that is found second among the three?

I suppose this would be very helpful in real time.

like image 271
Vijay Avatar asked Oct 24 '09 10:10

Vijay


1 Answers

Use the bar (|), escaped (i.e., with a backslash in front, so that it is not interpreted as a literal bar):

/string1\|string2\|string3

Note that the colon (:) is not necessary. In command mode, you can just type a slash (/); no need to type a colon first.

like image 152
Stephan202 Avatar answered Nov 17 '22 00:11

Stephan202