When running the normal git diff
I get the intuitive colors that I'm used to:
Red for deleted, green for added, white for unchanged.
But when I run git commit -v
, the included diff that opens in the editor has weird colors that I'm not used to, and so parsing the meaning of the diff is more difficult:
White/gray for deleted, cyan for added, white for unchanged? What is that?
What can I do so that the diff inside the editor on verbose commits has the same colors as when running git diff
directly?
I am using MacOS and vim as editor (git config --global core.editor /usr/bin/vim
)
git commit -v
opens a file named COMMIT_EDITMSG
. Vim (8.2) will set the filetype
of a file with this name to gitcommit
.
The corresponding syntax rules ($VIMRUNTIME/syntax/gitcommit.vim
) reference the syntax/diff.vim
rules, which make the lines starting with +
and -
into diffAdded
and diffRemoved
syntax items, respectively.
You need to set up your colorscheme and/or terminal colors so that diffAdded
looks green and diffRemoved
looks red.
Check with :hi diffAdded
and :hi diffRemoved
why they are currently not green and red.
e.g. you may see
:hi diffAdded
diffAdded xxx links to Identifier
and then
:hi Identifier
Identifier xxx term=underline cterm=bold ctermfg=6 guifg=palegreen
To override the specific highlight groups relevant to verbose Git commits, one might add something like this to their .vimrc
:
function! MyHighlights() abort
highlight diffAdded ctermfg=2 guifg=#67c12c
highlight diffRemoved ctermfg=1 guifg=#b82e19
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyHighlights()
augroup END
If you don't already specify a colorscheme
, you also need to add this to trigger the ColorScheme
event:
colorscheme default
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With