Faster Vim Searching for Rails Projects

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.

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

let g:ackprg = 'ag --nogroup --nocolor --column'

Setup a sensible, .agignore file in the root of your project. Here’s mine for my current Rails
project:

tmp
log
chef
coverage
perf
spec/vcr
vendor/

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.

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.