Itai Ganot
Itai Ganot

Reputation: 6333

Vim: How to search for more than one word in the same search?

Is it possible to search within vim for more than one word?

For example: Let's say i'm inside vim and I press / in order to start a search for a certain word, is it possible to search for more than one word in the same search?

Upvotes: 2

Views: 161

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172758

If you do this often, my SearchAlternatives plugin may be useful to you.

The plugin provides mappings and commands to add and subtract alternative branches to the current search pattern. Currently searching for "foo", but also want to find matches for "bar"? You could type /foo\|bar<CR> or /<C-R>/\|bar<CR>, but once you want to limit the search to whole \<words\> (like the * command), and juggle several alternatives, adding and dropping them as you search, this plugin is quicker than manually editing the search command-line (which you can still do).

Upvotes: 1

romainl
romainl

Reputation: 196856

Yes, you can have several branches in a search pattern:

/foo\|bar

See :help \|.

Upvotes: 4

Peter Gibson
Peter Gibson

Reputation: 19574

Use the OR operator

/first\|second

Upvotes: 2

Related Questions