Replacing Ack with Ag
I used grep to search code for a bit over a decade. I switched to ack to get more quicker searches without the distractions of svn/git metadata and other non-code files. After a very nice five years of ack, I’ve switched to ag. I’ve been recommending it to other devs for a year or two (it’s faster than ack with a couple really nice features like obeying .gitignore configs), but only took the time to switch this week.
On Arch, installing was as simple as:
` pacman -S the_silver_searcher pacman -Rns ack `{lang=”bash”}
Updating my vimrc’s section for ack.vim was supposed to be straightforward but turned into a pain in the ass. In my vimrc I had:
" Use Ack instead of Grep when available if executable("ack") set grepprg=ack\-H\--nogroup\--nocolor endif command! -nargs=* -complete=file Ack call Ack() nmap a :Ack nmap A :Ack
{lang=”vim”}
I added the following after the ‘endif’, so my config falls back to ack on systems without ack:
` if executable(“ag”) let g:ackprg=”ag –nogroup –nocolor –column” set grepprg=ag\ –vimgrep\ $* set grepformat=%f:%l%c%m endif `{lang=”vim”}
Unfortunately, ack.vim got loaded by pathogen after .vimrc, so the let g:ackprg
default at the top was overriding my config. This drove me insane for a few minutes, and maybe there’s some clever way to say that my setting should not be replaceable, but I just commented out the line in ~/.vim/bundle/ack.vim/plugin/ack.vim and moved on with my life.
Then I edited my `a` alias, and aliased “ack”, knowing that I’ll make that mistake for a few months:
` alias a=’ag’ alias ack=’ag’ `{lang=”bash”}
Last, I added a ~/.agignore
to ignore rcov output:
` coverage rcov `{lang=”agignore”}
Not much config to update, but ag is sharply faster drop-in replacement for ack.