Skip to content

Instantly share code, notes, and snippets.

@Dkendal
Created May 16, 2014 20:01
Show Gist options
  • Save Dkendal/9c5244f04755f0eb7e3e to your computer and use it in GitHub Desktop.
Save Dkendal/9c5244f04755f0eb7e3e to your computer and use it in GitHub Desktop.
A vim operator function to search for a word with a motion
nnoremap <leader>g :set operatorfunc=AgOperator<cr>g@
vnoremap <leader>g :<c-u>call AgOperator(visualmode())<cr>
function! AgOperator(type)
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
silent execute "Ag " . shellescape(@@) . " ."
copen
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment