From 8db2fc5da0d5ad02fa4fa38ae16dc2fad9bfd201 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Sat, 25 Apr 2020 11:17:34 +0100 Subject: [PATCH] Set correct background on existing GitGutter* highlight groups Previously if the user or the colourscheme had already defined GitGutter* highlight groups, the plugin would leave their backgrounds alone. This pushed the responsibility for figuring out and specifying the correct backgrounds onto the user or colourscheme maintainer. With this change the plugin now sets the correct background on existing GitGutter* highlight groups. Also, the documentation was simplified so it is clearer how to set your own colours for the signs. --- README.mkd | 27 ++++++++------------------- autoload/gitgutter/highlight.vim | 9 +++++++++ doc/gitgutter.txt | 16 +++++----------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/README.mkd b/README.mkd index 1562cd4..c49289f 100644 --- a/README.mkd +++ b/README.mkd @@ -318,31 +318,20 @@ let g:gitgutter_sign_allow_clobber = 1 #### Signs' colours and symbols -By default vim-gitgutter uses your colourscheme's `Diff*` highlight groups' foreground colours for the signs' foreground colours. For example, your `DiffAdd` foreground colour will be used for the `+` sign's foreground colour. +If you or your colourscheme has defined `GitGutter*` highlight groups, the plugin will use those for the signs' colours. -The signs' background colours will all be set to the sign column's background colour. +Otherwise it will use your colourscheme's `Diff*` highlight groups. -If you don't like the default colours, you can either fix your colourscheme's `Diff*` highlights or configure your own `GitGutter*` highlight groups. These groups are: +Either way the signs' background colours will be set to the sign column's background colour. + +If you don't like the colours, specify the ones you want in your vimrc (see `:help highlight-guifg` and `:help highlight-ctermfg`). For example, to get vim-gitgutter's original colours (based on git-diff's colours in my terminal): ```viml -GitGutterAdd " an added line (default: links to DiffAdd) -GitGutterChange " a changed line (default: links to DiffChange) -GitGutterDelete " at least one removed line (default: links to DiffDelete) -GitGutterChangeDelete " a changed line followed by at least one removed line (default: links to GitGutterChange) +highlight GitGutterAdd guifg=#009900 ctermfg=2 +highlight GitGutterChange guifg=#bbbb00 ctermfg=3 +highlight GitGutterDelete guifg=#ff2222 ctermfg=1 ``` -You can either set these with `highlight GitGutterAdd {key}={arg}...` or link them to existing highlight groups with, say, `highlight link GitGutterAdd MyDiffAdd`. - -To get vim-gitgutter's original colours (based on git-diff's colours in my terminal): - -```viml -highlight GitGutterAdd guifg=#009900 guibg= ctermfg=2 ctermbg= -highlight GitGutterChange guifg=#bbbb00 guibg= ctermfg=3 ctermbg= -highlight GitGutterDelete guifg=#ff2222 guibg= ctermfg=1 ctermbg= -``` - -– where you would replace `` and `` with the background colour of your `SignColumn` in the gui and the terminal respectively. For example, with the solarized colorscheme and a dark background, `guibg=#073642` and `ctermbg=0`. - To customise the symbols, add the following to your `~/.vimrc`: ```viml diff --git a/autoload/gitgutter/highlight.vim b/autoload/gitgutter/highlight.vim index e8ac1a2..9839cfb 100644 --- a/autoload/gitgutter/highlight.vim +++ b/autoload/gitgutter/highlight.vim @@ -84,6 +84,15 @@ function! gitgutter#highlight#define_highlights() abort highlight default link GitGutterChangeDeleteInvisible GitGutterChangeInvisible " When they are visible. + + " If GitGutter* highlights are already defined, either by the user or the colourscheme, + " set their backgrounds to the sign column's. + for type in ["Add", "Change", "Delete"] + if hlexists("GitGutter".type) + execute "highlight GitGutter".type." guibg=".guibg." ctermbg=".ctermbg + endif + endfor + " By default use Diff* foreground colors with SignColumn's background. for type in ['Add', 'Change', 'Delete'] let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type) diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index b2278c8..e8f8178 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -529,20 +529,14 @@ of the current window instead of the global quickfix list. =============================================================================== HIGHLIGHTS *gitgutter-highlights* -To change the signs' colours, set up the following highlight groups in your -colorscheme or |vimrc|: +To change the signs' colours, specify these highlight groups in your |vimrc|: > - GitGutterAdd " an added line - GitGutterChange " a changed line - GitGutterDelete " at least one removed line - GitGutterChangeDelete " a changed line followed by at least one removed line + highlight GitGutterAdd guifg=#009900 ctermfg=2 + highlight GitGutterChange guifg=#bbbb00 ctermfg=3 + highlight GitGutterDelete guifg=#ff2222 ctermfg=1 < -You can either set these with `highlight GitGutterAdd {key}={arg}...` or link -them to existing highlight groups with, say: -> - highlight link GitGutterAdd MyDiffAdd -< +See |highlight-guifg| and |highlight-ctermfg| for the values you can use. To change the line highlights, set up the following highlight groups in your colorscheme or |vimrc|: