Using ack for vim's :grep

hanekomu on 2007-10-23T18:50:12

If you want the power of Perl regular expressions in with vim's :grep command, put this line into your .vimrc:

set grepprg=ack\ --nocolor\ --nogroup\ '$*'\ *\ /dev/null

Now you can use ack from within vim like this:

:grep some search.*string

If you want to be able to move through the results (opening each one in the editor on the line the result occurred), add these lines to your .vimrc:

nmap <C-v><C-n> :cnext<CR>
imap <C-v><C-n> <Esc><C-v><C-n>
nmap <C-v><C-p> :cprev<CR>
imap <C-v><C-p> <Esc><C-v><C-p>

Now <C-v><C-n> will go to the next search result, both from command and insert mode, and <C-v><C-p> will go to the previous search result.