diff --git a/README.mkd b/README.mkd index cd66f29..e8c7b51 100644 --- a/README.mkd +++ b/README.mkd @@ -271,6 +271,14 @@ If you have `grep` aliased to something which changes its output, for example `g let g:gitgutter_escape_grep = 1 ``` +#### Use a custom `grep` command + +If you use an alternative to grep, you can tell vim-gitgutter to use it here. + +```viml +let g:gitgutter_grep_command = ' | grep --color=never -e "^@@"' +``` + #### To turn off vim-gitgutter by default Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`. diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 2ff7f5b..7efaaa8 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -1,11 +1,16 @@ -let s:grep_available = executable('grep') -if s:grep_available - let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep') - let s:grep_help = gitgutter#utility#system('grep --help') - if s:grep_help =~# '--color' - let s:grep_command .= ' --color=never' +if exists('g:gitgutter_grep_command') + let s:grep_available = 1 + let s:grep_command = g:gitgutter_grep_command +else + let s:grep_available = executable('grep') + if s:grep_available + let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep') + let s:grep_help = gitgutter#utility#system('grep --help') + if s:grep_help =~# '--color' + let s:grep_command .= ' --color=never' + endif + let s:grep_command .= ' -e '.gitgutter#utility#shellescape('^@@ ') endif - let s:grep_command .= ' -e '.gitgutter#utility#shellescape('^@@ ') endif let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@' diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index b869800..c61ad05 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -119,6 +119,7 @@ You can customise: - Line highlights - Extra arguments for git-diff - Key mappings +- The grep executable used - Whether or not to escape grep (defaults to no) - Whether or not vim-gitgutter is on initially (defaults to on) - Whether or not signs are shown (defaults to yes) @@ -214,6 +215,11 @@ To change the hunk-staging/reverting/previewing maps (defaults shown): TO ESCAPE GREP +To use a custom invocation for grep, use this: +> + let g:gitgutter_grep_command = ' | grep --color=never -e "^@@ "' +< + To avoid any alias you have for grep, use this: > let g:gitgutter_escape_grep = 1