Skip to content

Commit 1a13951

Browse files
committed
Simplify tradeoff between accuracy and speed.
If the plugin slows down your Vim too much, you can have it run less often by setting `g:gitgutter_eager = 0`. This replaces the former options `g:gitgutter_on_bufenter` and `g:gitgutter_on_focusgained`.
1 parent b63d3c6 commit 1a13951

File tree

3 files changed

+19
-45
lines changed

3 files changed

+19
-45
lines changed

README.mkd

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ You can customise:
8181
* Whether or not vim-gitgutter is on initially (defaults to on)
8282
* Whether or not signs are shown (defaults to yes)
8383
* Whether or not line highlighting is on initially (defaults to off)
84-
* Whether or not vim-gitgutter runs on `BufEnter` (defaults to yes)
85-
* Whether or not vim-gitgutter runs for all visible buffers on `FocusGained` (defaults to yes)
84+
* Whether or not vim-gitgutter runs eagerly (defaults to yes)
8685

8786
Please note that vim-gitgutter won't override any colours or highlights you've set in your colorscheme.
8887

@@ -171,26 +170,19 @@ Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`.
171170
Add `let g:gitgutter_highlight_lines = 1` to your `~/.vimrc`.
172171

173172

174-
#### To stop vim-gitgutter running on `BufEnter`
173+
#### To stop vim-gitgutter running eagerly
175174

176-
This is on by default but causes a noticeable lag for some people. To turn it off, add this to your `~/.vimrc`:
177-
178-
```
179-
let g:gitgutter_on_bufenter = 0
180-
```
181-
182-
If you turn it off, vim-gitgutter will instead run every time you read or write a buffer.
175+
By default the plugin runs every time you read a file, on `BufEnter`, `TabEnter` and `FocusGained`.
183176

177+
This can cause a noticeable lag for some people so you can set the plugin to run instead only when you read or write a file.
184178

185-
#### To stop vim-gitgutter running for all visible buffers on `FocusGained`
179+
To turn off eager execution, add this to your `~/.vimrc`:
186180

187-
This is on by default but causes a noticeable lag for some people. To turn it off, add this to your `~/.vimrc`:
188-
189-
```viml
190-
let g:gitgutter_all_on_focusgained = 0
181+
```
182+
let g:gitgutter_eager = 0
191183
```
192184

193-
Note that this is always off with gVim on Windows due to a Vim/shell bug causing an infinite loop.
185+
Note that `FocusGained` cannot be used with gVim on Windows due to a Vim/shell bug causing an infinite loop.
194186

195187

196188
### FAQ
@@ -201,11 +193,10 @@ Your colorscheme is configuring the `SignColumn` highlight group weirdly. Pleas
201193

202194
> There's a noticeable lag when vim-gitter runs; how can I avoid it?
203195
204-
By default vim-gitgutter runs often so the signs are as accurate as possible. However on some systems this causes a noticeable lag. If you would like to trade a little accuracy for speed, add one or both of these to your `~/.vimrc`:
196+
By default vim-gitgutter runs often so the signs are as accurate as possible. However on some systems this causes a noticeable lag. If you would like to trade a little accuracy for speed, add this to your `~/.vimrc`:
205197

206198
```viml
207-
let g:gitgutter_on_bufenter = 0
208-
let g:gitgutter_all_on_focusgained = 0
199+
let g:gitgutter_eager = 0
209200
```
210201

211202
> Why is no sign shown if I delete the first line(s) in a file?

doc/gitgutter.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ You can customise:
9999
- Whether or not vim-gitgutter is on initially (defaults to on)
100100
- Whether or not signs are shown (defaults to yes)
101101
- Whether or not line highlighting is on initially (defaults to off)
102-
- Whether or not vim-gitgutter runs on `BufEnter` (defaults to yes)
103-
- Whether or not vim-gitgutter runs for all buffers on `FocusGained` (defaults
104-
to yes)
102+
- Whether or not vim-gitgutter runs eagerly (defaults to yes)
105103

106104
Please note that vim-gitgutter won't override any colours or highlights you've
107105
set in your colorscheme.
@@ -203,18 +201,11 @@ Add to your |vimrc|
203201
let g:gitgutter_highlight_lines = 1
204202
<
205203

206-
TO STOP VIM-GITGUTTER RUNNING ON |BUFENTER|
204+
TO STOP VIM-GITGUTTER RUNNING EAGERLY
207205

208206
Add to your |vimrc|
209207
>
210-
let g:gitgutter_on_bufenter = 0
211-
<
212-
213-
TO STOP VIM-GITGUTTER RUNNING ON |FOCUSGAINED|
214-
215-
Add to your |vimrc|
216-
>
217-
let g:gitgutter_all_on_focusgained = 0
208+
let g:gitgutter_eager = 0
218209
<
219210

220211

plugin/gitgutter.vim

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ call s:set('g:gitgutter_signs', 1)
2020
call s:set('g:gitgutter_highlight_lines', 0)
2121
let s:highlight_lines = g:gitgutter_highlight_lines
2222
call s:set('g:gitgutter_sign_column_always', 0)
23-
call s:set('g:gitgutter_on_bufenter', 1)
24-
call s:set('g:gitgutter_all_on_focusgained', 1)
23+
call s:set('g:gitgutter_eager' , 1)
2524
call s:set('g:gitgutter_sign_added', '+')
2625
call s:set('g:gitgutter_sign_modified', '~')
2726
call s:set('g:gitgutter_sign_removed', '_')
@@ -118,10 +117,6 @@ function! s:snake_case_to_camel_case(text)
118117
return substitute(a:text, '\v(.)(\a+)(_(.)(.+))?', '\u\1\l\2\u\4\l\5', '')
119118
endfunction
120119

121-
function! s:buffers()
122-
return filter(range(1, bufnr('$')), 'buflisted(v:val)')
123-
endfunction
124-
125120
" }}}
126121

127122
" Highlights and signs {{{
@@ -405,8 +400,7 @@ endfunction
405400
" Public interface {{{
406401

407402
function! GitGutterAll()
408-
let buffer_ids = g:gitgutter_on_bufenter ? tabpagebuflist() : s:buffers()
409-
for buffer_id in buffer_ids
403+
for buffer_id in tabpagebuflist()
410404
call GitGutter(expand('#' . buffer_id . ':p'))
411405
endfor
412406
endfunction
@@ -532,16 +526,14 @@ endfunction
532526

533527
augroup gitgutter
534528
autocmd!
535-
if g:gitgutter_on_bufenter
529+
if g:gitgutter_eager
536530
autocmd BufEnter,BufWritePost,FileWritePost * call GitGutter(s:current_file())
537-
else
538-
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter(s:current_file())
539-
endif
540-
if g:gitgutter_all_on_focusgained
531+
autocmd TabEnter * call GitGutterAll()
541532
if !has('gui_win32')
542533
autocmd FocusGained * call GitGutterAll()
543534
endif
544-
autocmd TabEnter * call GitGutterAll()
535+
else
536+
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter(s:current_file())
545537
endif
546538
autocmd ColorScheme * call s:define_sign_column_highlight() | call s:define_highlights()
547539
augroup END

0 commit comments

Comments
 (0)