From 1a13951fc55eef71460c80e24c5b726a59bc9618 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 17 Apr 2013 10:39:57 +0200 Subject: [PATCH] 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`. --- README.mkd | 31 +++++++++++-------------------- doc/gitgutter.txt | 15 +++------------ plugin/gitgutter.vim | 20 ++++++-------------- 3 files changed, 20 insertions(+), 46 deletions(-) diff --git a/README.mkd b/README.mkd index 52b7a33..6c56d56 100644 --- a/README.mkd +++ b/README.mkd @@ -81,8 +81,7 @@ You can customise: * Whether or not vim-gitgutter is on initially (defaults to on) * Whether or not signs are shown (defaults to yes) * Whether or not line highlighting is on initially (defaults to off) -* Whether or not vim-gitgutter runs on `BufEnter` (defaults to yes) -* Whether or not vim-gitgutter runs for all visible buffers on `FocusGained` (defaults to yes) +* Whether or not vim-gitgutter runs eagerly (defaults to yes) Please note that vim-gitgutter won't override any colours or highlights you've set in your colorscheme. @@ -171,26 +170,19 @@ Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`. Add `let g:gitgutter_highlight_lines = 1` to your `~/.vimrc`. -#### To stop vim-gitgutter running on `BufEnter` +#### To stop vim-gitgutter running eagerly -This is on by default but causes a noticeable lag for some people. To turn it off, add this to your `~/.vimrc`: +By default the plugin runs every time you read a file, on `BufEnter`, `TabEnter` and `FocusGained`. + +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. + +To turn off eager execution, add this to your `~/.vimrc`: ``` -let g:gitgutter_on_bufenter = 0 +let g:gitgutter_eager = 0 ``` -If you turn it off, vim-gitgutter will instead run every time you read or write a buffer. - - -#### To stop vim-gitgutter running for all visible buffers on `FocusGained` - -This is on by default but causes a noticeable lag for some people. To turn it off, add this to your `~/.vimrc`: - -```viml -let g:gitgutter_all_on_focusgained = 0 -``` - -Note that this is always off with gVim on Windows due to a Vim/shell bug causing an infinite loop. +Note that `FocusGained` cannot be used with gVim on Windows due to a Vim/shell bug causing an infinite loop. ### FAQ @@ -201,11 +193,10 @@ Your colorscheme is configuring the `SignColumn` highlight group weirdly. Pleas > There's a noticeable lag when vim-gitter runs; how can I avoid it? -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`: +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`: ```viml -let g:gitgutter_on_bufenter = 0 -let g:gitgutter_all_on_focusgained = 0 +let g:gitgutter_eager = 0 ``` > Why is no sign shown if I delete the first line(s) in a file? diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index c78981d..88fa2a2 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -99,9 +99,7 @@ You can customise: - Whether or not vim-gitgutter is on initially (defaults to on) - Whether or not signs are shown (defaults to yes) - Whether or not line highlighting is on initially (defaults to off) -- Whether or not vim-gitgutter runs on `BufEnter` (defaults to yes) -- Whether or not vim-gitgutter runs for all buffers on `FocusGained` (defaults - to yes) +- Whether or not vim-gitgutter runs eagerly (defaults to yes) Please note that vim-gitgutter won't override any colours or highlights you've set in your colorscheme. @@ -203,18 +201,11 @@ Add to your |vimrc| let g:gitgutter_highlight_lines = 1 < -TO STOP VIM-GITGUTTER RUNNING ON |BUFENTER| +TO STOP VIM-GITGUTTER RUNNING EAGERLY Add to your |vimrc| > - let g:gitgutter_on_bufenter = 0 -< - -TO STOP VIM-GITGUTTER RUNNING ON |FOCUSGAINED| - -Add to your |vimrc| -> - let g:gitgutter_all_on_focusgained = 0 + let g:gitgutter_eager = 0 < diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 90f97f0..9cb838d 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -20,8 +20,7 @@ call s:set('g:gitgutter_signs', 1) call s:set('g:gitgutter_highlight_lines', 0) let s:highlight_lines = g:gitgutter_highlight_lines call s:set('g:gitgutter_sign_column_always', 0) -call s:set('g:gitgutter_on_bufenter', 1) -call s:set('g:gitgutter_all_on_focusgained', 1) +call s:set('g:gitgutter_eager' , 1) call s:set('g:gitgutter_sign_added', '+') call s:set('g:gitgutter_sign_modified', '~') call s:set('g:gitgutter_sign_removed', '_') @@ -118,10 +117,6 @@ function! s:snake_case_to_camel_case(text) return substitute(a:text, '\v(.)(\a+)(_(.)(.+))?', '\u\1\l\2\u\4\l\5', '') endfunction -function! s:buffers() - return filter(range(1, bufnr('$')), 'buflisted(v:val)') -endfunction - " }}} " Highlights and signs {{{ @@ -405,8 +400,7 @@ endfunction " Public interface {{{ function! GitGutterAll() - let buffer_ids = g:gitgutter_on_bufenter ? tabpagebuflist() : s:buffers() - for buffer_id in buffer_ids + for buffer_id in tabpagebuflist() call GitGutter(expand('#' . buffer_id . ':p')) endfor endfunction @@ -532,16 +526,14 @@ endfunction augroup gitgutter autocmd! - if g:gitgutter_on_bufenter + if g:gitgutter_eager autocmd BufEnter,BufWritePost,FileWritePost * call GitGutter(s:current_file()) - else - autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter(s:current_file()) - endif - if g:gitgutter_all_on_focusgained + autocmd TabEnter * call GitGutterAll() if !has('gui_win32') autocmd FocusGained * call GitGutterAll() endif - autocmd TabEnter * call GitGutterAll() + else + autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter(s:current_file()) endif autocmd ColorScheme * call s:define_sign_column_highlight() | call s:define_highlights() augroup END