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
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
Use:
:set magic
/foo.*bar
The 'magic' setting determines how VIM treats special characters in regular expressions. When it's off VIM treats all chars literally, meaning that the expression you wrote foo.*bar
will actually search for that string. However, when 'magic' is on then special regex chars get their special meaning and it works more like you expect. 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.