From 7bb8c2de96641e3123d39fd6c5268c9a16222906 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 2 Nov 2018 17:13:05 -0400 Subject: [PATCH] vim: Create :GitGrep command --- vim/vimrc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index aa64998..68ec8d8 100644 --- 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(''), '#', '\\#', '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(''), '#', '\\#', 'g') + call GitGrep(word) +endfunction + function! s:InGitRepo() abort if has('win64') || has('win32') let fsep = '\' @@ -250,4 +254,9 @@ nnoremap G :call GitGrepWordUnderCursor():copen nnoremap w :set list! " }}} +" COMMANDS {{{ +command! -nargs=1 GitGrep call GitGrep('') +command! CD exe 'cd ' . expand('%:h') +" }}} + " vim:fdm=marker:sts=4:sw=4 -- libgit2 0.28.4