Load a different color scheme when using vimdiff

How to load a different color scheme while running vimdiff .

I want this because my current color scheme does not show some differences in vimdiff , For. for example, some diff is shown with the same color fg / bg. This makes it difficult to understand the differences. So every time I do vimdiff I have to do :colorscheme some_other_scheme

Can this be done in a .vimrc file?

+113
vim vimdiff
Jan 07 '10 at 9:22
source share
12 answers

If you are calling vimdiff from the command line, put the following in .vimrc :

 if &diff colorscheme some_other_scheme endif 

If you use vimdiff from within vim, you will either have to override the commands you use to start / stop (e.g. diffthis , diffoff ) using :cnoreabbr (there is also a plugin ) or use the auto command:

au FilterWritePre * if &diff | colorscheme xyz | endif

FilterWritePre is called before filtering through an external program (diff utility) and &diff -option is set to vim when switching to diff mode (among other things, see :help diff )

I'm not sure which auto-command to use to return to the original color scheme.

+99
Jan 07 '10 at 9:51 on
source share

I don’t know why vim uses so many colors to emphasize, this will not help you understand what is happening.

I changed my color scheme to use only one color to highlight (on the other to show where the difference is within the line), and this did my best.

Before

enter image description here

After

colorscheme_screenshot

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

 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 text color
  • ctermbg - set the backlight
  • DiffAdd - added line
  • DiffDelete - deleted line
  • DiffChange - part of the line has been changed (selection of the entire line)
  • DiffText is the exact part of the line that changed

I used this link as a reference for color numbers.

Note. I did not set the gui parameters because I use a different color scheme for macvim / gvim

+130
Jun 19 '13 at 5:18
source share

To answer my own question:

 if &diff colorscheme evening endif 
+40
Jan 07 '10 at 9:59
source share

I found that the easiest way is to insert this single line liner into the ~ / .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 
+17
Nov 13
source share

If you encounter unreadable color schemes (not only ugly, but also unreadable, like white text on a pink background), you can easily fix the use of 16 colors instead of 256 colors. Then you do not need to mess with color schemes.

The reason is that the color scheme of DiffChange bg defaults to DiffChange bg as "LightMagenta", which is displayed in very light pink in 256 colors. It is unreadable with white text. With 16 colors, LightMagenta is displayed in bright magenta, on which white text looks much better.

You can do 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, 16 colors are much more readable, without changing the color scheme.

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

+10
Feb 27 '16 at 22:32
source share

For people who use the very excellent Solarized , there is an option that provides high visibility for diff:

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

"normal" enter image description here

"tall" enter image description here

"low" enter image description here

+9
Jul 13 '15 at 11:35
source share

Another approach is to fix this color scheme.

As far as I know, there are usually four backlight groups compared to diff'ing: DiffAdd, DiffChange, DiffDelete, and DiffText. If you don’t want to worry about the syntax or customize the colors to your liking, perhaps you can copy the default color scheme under a different name to ~ / .vim / colors (create a directory if it does not exist) and copy paste the appropriate commands: hi from your alternate color scheme to the end of your new custom color scheme, without necessarily commenting on any other statements that are related to it.

And if the result is an obvious improvement, send an email accompanying your color scheme with your changes and ask him to study the problem. There is a good chance that he will thank you for your interest and that he will correct his color scheme so that other users also win.

+5
Jul 21 2018-12-21T00:
source share

/etc/vim/vimrc or ~/.vimrc : If using a dark background in the editing area and syntax highlighting enable this option also set background=dark

+5
Jun 07 '14 at 15:13
source share

molokai: molokai color scheme github: github color scheme The two github and molokai themes 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 ~ / .vimrc, you can choose github or molokai (the line starting with "is a comment):

 if &diff " colorscheme github colorscheme molokai endif 
+3
Nov 03 '18 at 11:02
source share

When using vimdiff from vim, I use the following:

 au BufEnter,BufNew * if &diff | syntax off | else | syntax on | endif 

The else clause is important because how do you get back to your previous configuration after you're done with diff'ing. Therefore, you can replace syntax off and syntax on with the corresponding colorscheme commands. This autocmd handles changing the settings and returning it when exiting vimdiff (I use Gdiff to be exact).

+2
Aug 16 '16 at 9:39 on
source share

my current color scheme does not properly show the differences in vimdiff, For. for example, some differences are displayed with the same color fg / bg

In fact, I found that the main culprit of the same color is fg / bg - because of a conflict between syntax highlighting and diffchechecheche. You can try to change the color scheme of differences, but it can be a game of hide and seek when you open files of different types (with different code syntax highlighting).

The right solution is to turn off syntax highlighting in vimdiff. You can enter:

:syntax off

Or, if you want to do this automatically every time, add this to the end of your ~/.vimrc :

 if &diff syntax off endif 
+2
Mar 02 '18 at 1:19
source share

To extend @dean and some other answers here, add this to your .vimrc :

 if &diff " colorscheme evening 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 endif 
0
Apr 04 '19 at 19:10
source share



All Articles