Dec 22, 2008

Integrate Ack with Vim

I've been a long time Vim user, but the searching in a project is the missing part in Vim compare to TextMate. I used to switch to a command line using 'grep' or 'rak'(a ruby gem). Finally there is good tip how to integrate it into vim: Ack plugin for Vim

Here is how I do it on my Mac:

1. Install File-Next
2. Install ack
3. Edit your vimrc, add:
set grepprg=ack

4. Create a ack.vim in your .vim/plugin/
" all credits to antoine,
" more details see: http://blog.ant0ine.com/2007/03/ack_and_vim_integration.html
function! Ack(args)
let grepprg_bak=&grepprg
set grepprg=ack\ -H\ --nocolor\ --nogroup
execute "silent! grep " . a:args
botright copen
let &grepprg=grepprg_bak
endfunction
command! -nargs=* -complete=file Ack call Ack(<q-args>)
view raw ack.vim hosted with ❤ by GitHub


Fire up your vim:

:Ack text_to_search_in_current_path

No comments: