How can I search in vim for a line that has 2 specific words?


How can I search in vim for a line that has 2 specific words?



I want to find a line that has both 'foo' and 'bar' in this order but not necessarily next to each other.

I tried the following and it didn't work:

/foo.*bar 



Iterate through search results by column

1:



How can I custom indent a file with vim?
Use:.
How may I scroll with vim into a big file?
:set magic /foo.*bar 
The 'magic' setting determines how VIM treats special characters in regular expressions.


VIM syntax file for specman
When it's off VIM treats all chars literally, meaning that the expression you wrote foo.*bar will actually search for that string.


vi, vim buffers overrun
However, when 'magic' is on then special regex chars get their special meaning and it works more like you expect.


Vimdiff current line compare
It is recommended to always use :set magic unless dealing with really old Vi scripts, so just add it to your vimrc and you'll be set..
How can I read RSS in VIM?


Undo Close Tab in Vim

2:


Works for me: .
/text.*text2 


3:


There is also a great plugin to a do Boolean search in vim:. LogiPat plugin.



92 out of 100 based on 52 user ratings 302 reviews