changeset 236:639222e1ab7b

Add Ag plugin
author zegervdv <zegervdv@me.com>
date Sat, 07 Feb 2015 22:12:55 +0100
parents d29157c632c0
children 6f3eb83613bf
files vimrc
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/vimrc	Fri Jan 30 16:08:56 2015 +0100
+++ b/vimrc	Sat Feb 07 22:12:55 2015 +0100
@@ -32,6 +32,7 @@
 
 " Moving in files
 Plug 'wellle/targets.vim'
+Plug 'rking/ag.vim'
 
 " Command line
 Plug 'tpope/vim-eunuch', { 'on' : ['Remove', 'Unlink', 'Move', 'Rename', 'Mkdir', 'Chmod', 'Find', 'Locate', 'SudoEdit', 'SudoWrite']}
@@ -441,6 +442,29 @@
 " Swoop {{{
 let g:swoopUseDefaultKeyMap = 0
 " }}}
+" Ag {{{
+" Ack motions by Steve Losh, adapted for Ag
+nnoremap <silent> \a :set opfunc=<SID>AckMotion<CR>g@
+xnoremap <silent> \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! :Ag --literal " . shellescape(@@) . "\<cr>"
+ 
+    let @@ = reg_save
+endfunction
+" }}}
 
 " Load local vimrc
 if filereadable($HOME . "/.vimrc.local")