Ack Motion for Vim

master
Dustin Swan 10 years ago
parent a3478b3b5e
commit 2f0ba3df09

29
vimrc

@ -201,11 +201,6 @@ nnoremap <silent><leader>4 :! p4 edit %<cr>
" open vsplit and switch to it " open vsplit and switch to it
nnoremap <leader>v <c-w>v<c-w>l nnoremap <leader>v <c-w>v<c-w>l
" Ack
nnoremap <leader>a :Ack<space>
" use ag
let g:ackprg = 'ag --nogroup --nocolor --column'
" Buffer selection " Buffer selection
nnoremap <leader>l :ls<cr>:b<space> nnoremap <leader>l :ls<cr>:b<space>
@ -269,3 +264,27 @@ let g:calendar_google_calendar = 1
map / <Plug>(incsearch-forward) map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward) map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay) map g/ <Plug>(incsearch-stay)
" Ack
"nnoremap <leader>a :Ack<space>
" No wait, Ack motion! Thanks again sjl
nnoremap <silent> <leader>a :set opfunc=<SID>AckMotion<CR>g@
xnoremap <silent> <leader>a :<C-U>call <SID>AckMotion(visualmode())<CR>
function! s:CopyMotionForType(type)
if a:type ==# 'v'
silent execute "normal! `<" . a:type . "`>y"
elseif a:type ==# 'char'
silent execute "normal! `[v`]y"
endif
endfunction
function! s:AckMotion(type) abort
let reg_save = @@
call s:CopyMotionForType(a:type)
execute "normal! :Ack! --literal " . shellescape(@@) . "\<cr>"
let @@ = reg_save
endfunction

Loading…
Cancel
Save