VIM: ack instead of grep

I much prefer ack to the standard grep – it’s way better. If you are curious why – just open the ack page.
Replacing grep with ack in VIM is pretty easy: set grepprg=ack. But there’s a catch – ack does not output columns for search results, making search result navigation a nightmare – on each “:cn” VIM puts cursor at the beginning of the line and I have to do an additional search for the word. Definitely no fun!

Adding columns to ack turned out no big deal. Here’s how to do this (works for ack 1.86, so just get this version or tweak the patch file):

  1. Download Ack.pm.diff (taken from this thread: here, Eric Van Dewoestine, thanks a lot!).
  2. Find the location of Ack.pm in your system (may be multiple files), typically locate Ack.pm.
  3. Patch each Ack.pm: sudo patch -p0 -b < /path/to/Ack.pm.diff /path/to/Ack.pm (if you have Ack.pm installed per user, please remove sudo).
  4. In your vimrc add the following:
    set grepprg=ack --column
    set grepformat=%f:%l:%c:%m

Enjoy!

Explore posts in the same categories: Vim

3 Comments on “VIM: ack instead of grep”

  1. Andy Lester Says:

    I’m making an ack release today that will include a –with-column switch. Thanks for bringing it up again.


  2. [...] Настройка ack вместо grep для vim’a, VIM: ack instead of grep [...]


Comment: