Skip to content

Commit 95734c6

Browse files
h3xxairblade
authored andcommitted
Add support for option g:gitgutter_grep_command
With this change, setting `g:gitgutter_grep_command` to ' | grep --color=never -e "^@@ "'` greatly reduces startup time. Before this change, `diff.vim` was a major bottleneck because it calls `grep --help`. This is mostly unnecessary except in a few cases where the user is running a nonstandard version of grep. `vim --startuptime start.out large_file.sql` before: times in msec clock self+sourced self: sourced script clock elapsed: other lines 000.026 000.026: --- VIM STARTING --- [...] 068.463 003.645 003.500: sourcing /home/dchurch/.vim/plugin/gitgutter.vim [...] 150.957 000.208 000.208: sourcing /home/dchurch/.vim/autoload/gitgutter.vim 151.294 000.196 000.196: sourcing /home/dchurch/.vim/autoload/gitgutter/utility.vim 165.059 012.619 012.619: sourcing /home/dchurch/.vim/autoload/gitgutter/diff.vim 236.901 000.188 000.188: sourcing /home/dchurch/.vim/autoload/gitgutter/hunk.vim 237.289 000.233 000.233: sourcing /home/dchurch/.vim/autoload/gitgutter/sign.vim [...] 337.673 000.004: --- VIM STARTED --- After change, and setting `g:gitgutter_grep_command = ' | grep --color=never -e "^@@ "'`: 000.026 000.026: --- VIM STARTING --- [...] 064.873 002.713 002.591: sourcing /home/dchurch/.vim/plugin/gitgutter.vim [...] 134.109 000.149 000.149: sourcing /home/dchurch/.vim/autoload/gitgutter.vim 134.337 000.147 000.147: sourcing /home/dchurch/.vim/autoload/gitgutter/utility.vim 135.411 000.232 000.232: sourcing /home/dchurch/.vim/autoload/gitgutter/diff.vim 187.831 000.180 000.180: sourcing /home/dchurch/.vim/autoload/gitgutter/hunk.vim 188.223 000.175 000.175: sourcing /home/dchurch/.vim/autoload/gitgutter/sign.vim [...] 285.008 000.004: --- VIM STARTED ---
1 parent 4510e9b commit 95734c6

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

README.mkd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ If you have `grep` aliased to something which changes its output, for example `g
271271
let g:gitgutter_escape_grep = 1
272272
```
273273

274+
#### Use a custom `grep` command
275+
276+
If you use an alternative to grep, you can tell vim-gitgutter to use it here.
277+
278+
```viml
279+
let g:gitgutter_grep_command = ' | grep --color=never -e "^@@"'
280+
```
281+
274282
#### To turn off vim-gitgutter by default
275283

276284
Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`.

autoload/gitgutter/diff.vim

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
let s:grep_available = executable('grep')
2-
if s:grep_available
3-
let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep')
4-
let s:grep_help = gitgutter#utility#system('grep --help')
5-
if s:grep_help =~# '--color'
6-
let s:grep_command .= ' --color=never'
1+
if exists('g:gitgutter_grep_command')
2+
let s:grep_available = 1
3+
let s:grep_command = g:gitgutter_grep_command
4+
else
5+
let s:grep_available = executable('grep')
6+
if s:grep_available
7+
let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep')
8+
let s:grep_help = gitgutter#utility#system('grep --help')
9+
if s:grep_help =~# '--color'
10+
let s:grep_command .= ' --color=never'
11+
endif
12+
let s:grep_command .= ' -e '.gitgutter#utility#shellescape('^@@ ')
713
endif
8-
let s:grep_command .= ' -e '.gitgutter#utility#shellescape('^@@ ')
914
endif
1015
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
1116

doc/gitgutter.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ You can customise:
119119
- Line highlights
120120
- Extra arguments for git-diff
121121
- Key mappings
122+
- The grep executable used
122123
- Whether or not to escape grep (defaults to no)
123124
- Whether or not vim-gitgutter is on initially (defaults to on)
124125
- Whether or not signs are shown (defaults to yes)
@@ -214,6 +215,11 @@ To change the hunk-staging/reverting/previewing maps (defaults shown):
214215

215216
TO ESCAPE GREP
216217

218+
To use a custom invocation for grep, use this:
219+
>
220+
let g:gitgutter_grep_command = ' | grep --color=never -e "^@@ "'
221+
<
222+
217223
To avoid any alias you have for grep, use this:
218224
>
219225
let g:gitgutter_escape_grep = 1

0 commit comments

Comments
 (0)