Faster Vim Searching for Rails Projects

Written by

I often need to find a particular string inside of a project. One popular tool to do this is ack and, inside of vim to use the Ack.vim plugin. Until recently I’ve used ack almost everyday. However, ack can be slow, especially when you’re just searching for a string and not a pattern. I’ve found, for my usage The silver searcher to be a faster alternative. You give up the ability to look for patterns and instead must look for static strings, but as I looked through my shell history I found that I’ve used pattern matching once in the last year. Your mileage may vary but for me this is a huge speedup at almost no cost.

Here’s how to get going searching using the silver searcher:

  1. Install The Silver Searcher – Using your favorite package manager:

    brew install the_silver_searcher or apt-get install silversearcher-ag

  2. In your .vimrc tell Ack.vim to use the silver searcher; Add this line:

     let g:ackprg = 'ag --nogroup --nocolor --column'
  3. Setup a sensible, .agignore file in the root of your project. Here’s mine for my current Rails project:


You’ll either want to add .agignore' to your.gitignore` file if you think that this kind of configuration is personal or check it in if you think others on your team would agree with these changes.

At this point everything should continue to work as you expect in vim- Ack.vim will instead use the silver searcher, ignore the file paths you specified, and return a list of files (just faster!).

This has hugely helped speed up searching through the project and made it much easier to find what I’m looking for. In fact because I so rarely look for patterns I’ve gone so far as to alias ack to ag in my zshrc.


Comments or Questions? Contact Nick @nixterrimus on twitter.

Nick is a software engineer, geek, web enthusaist, open source contributor, home automation tinkerer, ocean admirer and all around general optimist living in San Francisco. Want to get in touch about professional matters? Nick Rowe is also available on LinkedIn.