Load different colorscheme when using vimdiff

I don't know why vim uses so many colors to highlight with, it doesn't really help you figure out what's going on.

I modified my colorscheme to only use one color to highlight (with another to show where theres a difference within a line) and it made all the difference.

Before

enter image description here

After

colorscheme_screenshot

I did this by adding the following to the end of my colorscheme file (~/.vim/colors/mycolorscheme.vim).

highlight DiffAdd    cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText   cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
  • cterm - sets the style
  • ctermfg - set the text color
  • ctermbg - set the highlighting
  • DiffAdd - line was added
  • DiffDelete - line was removed
  • DiffChange - part of the line was changed (highlights the whole line)
  • DiffText - the exact part of the line that changed

I used this link as a reference for the color numbers.

Note: I didn't set the gui options because I use a different colorscheme for macvim/gvim


If you're calling vimdiff from the command-line, put the following in your .vimrc:

if &diff
    colorscheme some_other_scheme
endif

If you're using vimdiff from within vim, you'd either have to override the commands you use to start/stop it (e.g. diffthis, diffoff) using :cnoreabbr (there's also a plugin) or use an autocommand:

au FilterWritePre * if &diff | colorscheme xyz | endif

FilterWritePre is called before filtering through an external program (the diff utility) and the &diff-option is set by vim when it's going into diff-mode (among others, see :help diff)

I'm not sure which autocommand to use to return to the original colorscheme though.