Skip to content

Instantly share code, notes, and snippets.

@egwynn
Created June 6, 2014 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egwynn/08dbb8b870b85cfe342a to your computer and use it in GitHub Desktop.
Save egwynn/08dbb8b870b85cfe342a to your computer and use it in GitHub Desktop.
Ggrep for <cword> (in current dir or in git root)
function! GitRoot()
let cmd="git rev-parse --show-toplevel"
let result=system(cmd)
if v:shell_error
echom "Error: [".result."] (\"".result."\")"
echom "Command: [".cmd."]"
return expand("%:p:h/")
endif
return result
endfunction
function! QFGGrep(path)
" let needle = s:get_visual_selection()
let needle = expand("<cword>")
execute "silent botright Ggrep -i ".needle." ".a:path
cwindow
endfunction
nnoremap <Leader>gg :call QFGGrep(expand("%:p:h/"))<CR>
nnoremap <Leader>ga :call QFGGrep(GitRoot())<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment