commit 7bb8c2de96641e3123d39fd6c5268c9a16222906 (patch)
parent 8157a6d3fc531d73abda72e6bea97dfb8aceb247
Author: Alexander <akarle@umass.edu>
Date: Fri, 2 Nov 2018 17:13:05 -0400
vim: Create :GitGrep command
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/vim/vimrc b/vim/vimrc
@@ -142,10 +142,9 @@ function! ToggleColorColumn() abort
endfunction
" Searches all of project for word under cursor
-function! GitGrepWordUnderCursor() abort
- let word = substitute(expand('<cword>'), '#', '\\#', 'g')
+function! GitGrep(word) abort
if s:InGitRepo()
- let raw = system('git grep -n ' . word)
+ let raw = system('git grep -n ' . a:word)
let matches = split(raw, '\n')
let qfitems = []
for m in matches
@@ -164,6 +163,11 @@ function! GitGrepWordUnderCursor() abort
endif
endfunction
+function! GitGrepWordUnderCursor() abort
+ let word = substitute(expand('<cword>'), '#', '\\#', 'g')
+ call GitGrep(word)
+endfunction
+
function! s:InGitRepo() abort
if has('win64') || has('win32')
let fsep = '\'
@@ -250,4 +254,9 @@ nnoremap <silent> <leader>G :call GitGrepWordUnderCursor()<CR>:copen<CR>
nnoremap <leader>w :set list!<CR>
" }}}
+" COMMANDS {{{
+command! -nargs=1 GitGrep call GitGrep('<args>')
+command! CD exe 'cd ' . expand('%:h')
+" }}}
+
" vim:fdm=marker:sts=4:sw=4