tags:

views:

117

answers:

2

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
+3  A: 

Works for me:

/text.*text2
Chris Kaminski
Works for me as well
Brian Ramsay
Ditto; case-insensitive: /FOO.*BAR\c
Dave Jarvis
+6  A: 

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.

spatz
I'm pretty sure this is a default nowadays (at least my vim's on windows).
Chris Kaminski
I agree, it is also the default for, but I don't know why it wasn't set for Sasha - perhaps he's using an older version or invoking vi instead of vim.
spatz