From 76d1cf609dbb00673a6e221f84a063c816d8eecb Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Thu, 30 Apr 2020 19:43:02 +0100 Subject: [PATCH] Do not set background on existing GitGutter* highlights unless requested If GitGutter* highlight groups already exist, they were declared deliberately (either by the colorscheme maintainer or the user). So do not adjust them. However if you would like to make the signs' backgrounds match the sign column, you can do this: let g:gitgutter_set_sign_backgrounds = 1 --- README.mkd | 10 ++++++---- autoload/gitgutter/highlight.vim | 7 ++++--- doc/gitgutter.txt | 15 +++++++++++---- plugin/gitgutter.vim | 1 + 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/README.mkd b/README.mkd index 810cf2d..350cebe 100644 --- a/README.mkd +++ b/README.mkd @@ -316,13 +316,15 @@ let g:gitgutter_sign_allow_clobber = 1 #### Signs' colours and symbols -If you or your colourscheme has defined `GitGutter*` highlight groups, the plugin will use those for the signs' colours. +If you or your colourscheme has defined `GitGutter*` highlight groups, the plugin will use them for the signs' colours. -Otherwise it will use your colourscheme's `Diff*` highlight groups. +If you want the background colours to match the sign column, but don't want to update the `GitGutter*` groups yourself, you can get the plugin to do it: -Either way the signs' background colours will be set to the sign column's background colour. +```viml +let g:gitgutter_set_sign_backgrounds = 1 +``` -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): +If no `GitGutter*` highlight groups exist, the plugin will check the `Diff*` highlight groups. If their foreground colours differ the plugin will use them; if not, these colours will be used: ```viml highlight GitGutterAdd guifg=#009900 ctermfg=2 diff --git a/autoload/gitgutter/highlight.vim b/autoload/gitgutter/highlight.vim index b2da79c..16f8195 100644 --- a/autoload/gitgutter/highlight.vim +++ b/autoload/gitgutter/highlight.vim @@ -76,11 +76,12 @@ function! gitgutter#highlight#define_highlights() abort highlight default link GitGutterChangeDeleteInvisible GitGutterChangeInvisible " When they are visible. - - " The background colours are set to the sign column's. for type in ["Add", "Change", "Delete"] if hlexists("GitGutter".type) - let [guifg, ctermfg] = s:get_foreground_colors('GitGutter'.type) + if g:gitgutter_set_sign_backgrounds + execute "highlight GitGutter".type." guibg=".guibg." ctermbg=".ctermbg + endif + continue elseif s:useful_diff_colours() let [guifg, ctermfg] = s:get_foreground_colors('Diff'.type) else diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index a5c3576..2d744a8 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -306,6 +306,7 @@ Signs:~ |g:gitgutter_sign_removed| |g:gitgutter_sign_removed_first_line| |g:gitgutter_sign_modified_removed| + |g:gitgutter_set_sign_backgrounds| Hunk previews:~ @@ -449,12 +450,14 @@ Defaults: You can use unicode characters but not images. Signs must not take up more than 2 columns. + *g:gitgutter_set_sign_backgrounds* +Default: 0 - Desired appearance Command ~ - Same as line-number column highlight clear SignColumn - User-defined (terminal Vim) highlight SignColumn ctermbg={whatever} - User-defined (graphical Vim) highlight SignColumn guibg={whatever} +Only applies to existing GitGutter* highlight groups. See +|gitgutter-highlights|. +Controls whether to override the signs' background colours to match the +|hl-SignColumn|. *g:gitgutter_preview_win_floating* Default: 0 (Vim) @@ -526,6 +529,10 @@ To change the signs' colours, specify these highlight groups in your |vimrc|: See |highlight-guifg| and |highlight-ctermfg| for the values you can use. +If you do not like the signs' background colours and you do not want to update +the GitGutter* highlight groups yourself, you can get the plugin to do it +|g:gitgutter_set_sign_backgrounds|. + To change the line highlights, set up the following highlight groups in your colorscheme or |vimrc|: > diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index f4f48c2..a7208ea 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -52,6 +52,7 @@ if (has('nvim-0.4.0') || exists('*sign_place')) && !exists('g:gitgutter_sign_all endif call s:set('g:gitgutter_sign_allow_clobber', 0) call s:obsolete('g:gitgutter_override_sign_column_highlight') +call s:set('g:gitgutter_set_sign_backgrounds', 0) call s:set('g:gitgutter_sign_added', '+') call s:set('g:gitgutter_sign_modified', '~') call s:set('g:gitgutter_sign_removed', '_')