'Find in files' in vim

I have been enjoying vim quite a bit recently, it is really starting to speed up my workflow. The learning curve is constant, however. The latest thing I have needed to know (and use quite a bit) is a 'find in files' feature. Vim has this built in with a plugin called 'vimgrep'. The documentation was pretty straight forward (:h vimgrep) but it wasn't immediately obvious how to do recursive searching. The solution was what vim calls 'starstar-wildcard' (essentially **)

This simple example produces a recursive search:

:vimgrep /myPattern/ **

The above example will search through everything though, including binary files (like pngs and such), so a little more instruction is needed.

:vimgrep /myPattern/ **/*.html

# this is also equivalent
:vim /myPattern/ **/*.html

Vim then gives you the first of the matches, you can cycle between them with :cnext/:cn and :cp/:cprevious.

If you have a lot of files to search through, :grep is faster.

:grep -Ir /myPattern/ *
The flags -Ir tell it 'not case sensitive, and recursive...please :)'

Not so hard after all, af

Posted

Jun 14, 2009
by AnonymousUser

Categories

General Posts

Tags

grep
vim