[Update 2010-09-20: tweaked to run the grep on the git root instead of whatever directory the current file is in.]
After many months of screwing around with git.vim and fugitive.vim, I have
finally found the perfect vim + git grep combination.
This incantation allows you to press <ctrl-x> twice on a symbol and have a
minibuf pop up with all the occurrences of that symbol within the project. You
can then jump to any occurrence by pressing enter on the corresponding line.
Place this in e.g. ~/.vim/plugin/git-grep.vim:
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 " . 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>
Nice done! Why don’t you make a plugin, I mean, github-git-something-like based, where we can install with pathogen? :-) May I suggest to change the global vars to script vars, as using the script name as namespace for the functions? Thanks!
Hi William, I just loved your plugin. Thanks for share it with us. But, there’s one annoying thing: when the word that I was looking for is found, it always open the first file in the search list. Could you fix it to just show up the results list, without open anything?
Lucas Vasconcelos
On Tue, Jul 19, 2011 at 9:48 AM, William Morgan <comments@all-thing.net>wrote:
[Final quote automatically elided. — ed.]