Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load different colorscheme when using vimdiff

Tags:

vim

vimdiff

People also ask

What do the colors mean in Vimdiff?

1. Difference in whole line – Blue Color and Hyphens. If line X is available in one file and not available in another file, then file containing the line will be highlighted with blue color, and the file without that line will be displayed with hypens and in light green color as shown below.

How do I change vim color scheme permanently?

How to Set Default Vim Color Scheme. Changes you have made to the color settings are not permanent. Once you close Vim, the color scheme returns to the default settings. To make the changes permanent, modify Vim's configuration file with the wanted color settings.

How do I add Colorscheme to Vim?

You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.


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.


To answer my own question:

if &diff
    colorscheme evening
endif

I found the easiest way was to paste this one-liner into my ~/.vimrc file:

" Fix the difficult-to-read default setting for diff text highlighting.  The
" bang (!) is required since we are overwriting the DiffText setting. The highlighting
" for "Todo" also looks nice (yellow) if you don't like the "MatchParen" colors.
highlight! link DiffText MatchParen

If you are encountering unreadable color schemes (not just ugly, but unreadable like white text on pink background), an easy fix may be to use 16 colors instead of 256 colors. Then you don't have to mess with the color schemes.

The reason is that the default vimdiff color scheme assigns DiffChange bg as "LightMagenta", which gets mapped to a very light pink in 256 colors. That is unreadable with white text. With 16 colors, the "LightMagenta" is mapped to a bold magenta, which white text shows up much better on.

You can give a quick test by doing something like this:

vimdiff <file1> <file2>
:set t_Co?    " print current setting (256 by default)
:highlight    " print highlighting scheme
:set t_Co=16  " set to 16 colors
:highlight    " print highlighting scheme

256-color screenshot enter image description here

16-color screenshot enter image description here

As you can see, the 16 colors is much more readable, without changing the color scheme.

To make this permanent, you can add set t_Co=16 to your .vimrc


molokai: molokai color scheme github: github color scheme The two themes github and molokai are equally beautiful.

curl -fLo ~/.vim/colors/molokai.vim --create-dirs https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim
curl -fLo ~/.vim/colors/github.vim --create-dirs https://raw.githubusercontent.com/endel/vim-github-colorscheme/master/colors/github.vim

Put the following code in your ~/.vimrc, you can choose github or molokai (a line starting with a " is a comment):

if &diff
"   colorscheme github
    colorscheme molokai
endif

For people that use the very excellent Solarized theme there's an option that turns on high visibility for diff mode:

" ~/vim.rc
" Set high visibility for diff mode
let g:solarized_diffmode="high"

"normal" enter image description here

"high" enter image description here

"low" enter image description here