Recursive searching in vim with grep – vimgrep
Posted on February 17th, 2009 in Everyday Tips, PHP, Ubuntu, Vim, Web Development | 1 Comment »

One of the smartest people I’ve ever digitally met, Ryan Paul, taught me this awesome tip for doing a project wide search in vim. I needed to look for all occurrences of the patter _Models_ in a PHP project I was working on and you can do it right inside of vim – the best text editor ever invented.
- Open vim and make sure you are in the top level folder of your project by typing :pwd
- Then type :vimgrep YourPattern **/*.php
- To open your search results in their own buffer type :copen
The **/ recursively searches through all your directories for you pattern. :copen opens the search results in their own buffer. You can use the arrow keys to move up and down through the list and hit enter to have it open that result in the main buffer. You can also use :cnext and :cprev to move to the next and previous items in the list. Perhaps you might bind those to keyboard shortcuts so you can move through the search results quickly.