1 " NOTE: You must, of course, install the ack script
4 " sudo apt-get install ack-grep
6 " let g:ackprg="ack-grep -H --nocolor --nogroup --column"
9 " sudo port install p5-app-ack
11 " Location of the ack utility
12 if !exists("g:ackprg")
13 let g:ackprg="ack -H --nocolor --nogroup --column"
16 function! s:Ack(cmd, args)
20 " If no pattern is provided, search for the word under the cursor
22 let l:grepargs = expand("<cword>")
24 let l:grepargs = a:args
27 " Format, used to manage column jump
31 let g:ackformat="%f:%l:%c:%m"
34 let grepprg_bak=&grepprg
35 let grepformat_bak=&grepformat
38 let &grepformat=g:ackformat
39 silent execute a:cmd . " " . l:grepargs
41 let &grepprg=grepprg_bak
42 let &grepformat=grepformat_bak
51 " TODO: Document this!
52 exec "nnoremap <silent> <buffer> q :ccl<CR>"
53 exec "nnoremap <silent> <buffer> t <C-W><CR><C-W>T"
54 exec "nnoremap <silent> <buffer> T <C-W><CR><C-W>TgT<C-W><C-W>"
55 exec "nnoremap <silent> <buffer> o <CR>"
56 exec "nnoremap <silent> <buffer> go <CR><C-W><C-W>"
58 " If highlighting is on, highlight the search keyword.
59 if exists("g:ackhighlight")
67 function! s:AckFromSearch(cmd, args)
68 let search = getreg('/')
69 " translate vim regular expression to perl regular expression.
70 let search = substitute(search,'\(\\<\|\\>\)','\\b','g')
71 call s:Ack(a:cmd, '"' . search .'" '. a:args)
74 command! -bang -nargs=* -complete=file Ack call s:Ack('grep<bang>',<q-args>)
75 command! -bang -nargs=* -complete=file AckAdd call s:Ack('grepadd<bang>', <q-args>)
76 command! -bang -nargs=* -complete=file AckFromSearch call s:AckFromSearch('grep<bang>', <q-args>)
77 command! -bang -nargs=* -complete=file LAck call s:Ack('lgrep<bang>', <q-args>)
78 command! -bang -nargs=* -complete=file LAckAdd call s:Ack('lgrepadd<bang>', <q-args>)
79 command! -bang -nargs=* -complete=file AckFile call s:Ack('grep<bang> -g', <q-args>)