Skip to content

Instantly share code, notes, and snippets.

@tcha-tcho
Created April 13, 2011 05:33
Show Gist options
  • Save tcha-tcho/917013 to your computer and use it in GitHub Desktop.
Save tcha-tcho/917013 to your computer and use it in GitHub Desktop.
A vim help to grep using the git root
let g:gitgrepprg="git\\ grep\\ -n"
let g:gitroot="`git rev-parse --show-cdup`"
function! GitGrep(args)
let grepprg_bak=&grepprg
exec "set grepprg=" . g:gitgrepprg
execute "silent! grep! -i -I -n " . a:args . " " . g:gitroot
botright copen
let &grepprg=grepprg_bak
exec "redraw!"
endfunction
func GitGrepWord()
normal! "zyiw
call GitGrep(getreg('z'))
endf
nmap <C-x><C-x> :call GitGrepWord()<CR>
command -nargs=? G call GitGrep(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment