diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index f803a24..1174c44 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -12,6 +12,8 @@ if v:version < 703 || (v:version == 703 && !has("patch105")) finish endif +let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '' : '' + function! s:set(var, default) abort if !exists(a:var) if type(a:default) @@ -226,7 +228,20 @@ nnoremap GitGutterPreviewHunk :call gitgutter#utility#warn('ple function! s:on_bufenter() call gitgutter#setup_maps() - if has('vim_starting') && !$VIM_GITGUTTER_TEST | return | endif + " To keep vim's start-up fast, do not process the buffer when vim is starting. + " Instead process it a short time later. Normally we would rely on our + " CursorHold autocommand to handle this but it turns out CursorHold is not + " guaranteed to fire if the user has not typed anything yet; so set up a + " timer instead. The disadvantage is that if CursorHold does fire, the + " plugin will do a round of unnecessary work; but since there will not have + " been any changes to the buffer since the first round, the second round + " will be cheap. + if has('vim_starting') && !$VIM_GITGUTTER_TEST + if exists('*timer_start') + call timer_start(&updatetime, 'GitGutterCursorHold') + endif + return + endif if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter let t:gitgutter_didtabenter = 0 @@ -236,6 +251,10 @@ function! s:on_bufenter() endif endfunction +function! GitGutterCursorHold(timer) + execute 'doautocmd' s:nomodeline 'gitgutter CursorHold' +endfunction + " Autocommands {{{ augroup gitgutter