5

/* This is coming directly from Molokai's issue #36. */

The problem

Molokai is a very nice theme for Vim but it has a terrible vimdiff highlighting (see left split, last 5 lines). + are not green and - are not red.

Bad syntax highlighting

I've been suggested by justinmk@GitHub to use the following ~/.vimrc (here's the gist).

syntax enable
let s:color_override_dark = '
    \ if &background == "dark"
    \ | hi StatusLine    guifg=#000000 guibg=#ffffff gui=NONE  ctermfg=16 ctermbg=15     cterm=NONE
    \ | hi CursorLine    guibg=#293739 ctermbg=236
    \ | hi PmenuSel      guibg=#0a9dff guifg=white   gui=NONE  ctermbg=39 ctermfg=white  cterm=NONE
    \ | hi PmenuSbar     guibg=#857f78
    \ | hi PmenuThumb    guifg=#242321
    \ | hi WildMenu      gui=NONE cterm=NONE guifg=#f8f6f2 guibg=#0a9dff ctermfg=255 ctermbg=39
    \ | hi DiffAdd       guifg=#ffffff guibg=#006600 gui=NONE  ctermfg=231  ctermbg=22   cterm=NONE 
    \ | hi DiffChange    guifg=#ffffff guibg=#007878 gui=NONE  ctermfg=231  ctermbg=30   cterm=NONE 
    \ | hi DiffDelete    guifg=#ff0101 guibg=#9a0000 gui=NONE  ctermfg=196  ctermbg=88   cterm=NONE 
    \ | hi DiffText      guifg=#000000 guibg=#ffb733 gui=NONE  ctermfg=000  ctermbg=214  cterm=NONE 
    \ | hi MatchParen    guifg=NONE   guibg=NONE gui=underline ctermfg=NONE ctermbg=NONE cterm=underline
    \ | endif
    \'

if has('vim_starting') "only on startup
  exe 'autocmd ColorScheme * '.s:color_override_dark
  " expects &runtimepath/colors/{name}.vim.
  silent! colorscheme molokai
endif

which unfortunately does not work for some reasons. Can someone point out what has been done wrongly?


The solution

Inserting the following code into ~/.vimrc fixes the problem stated above.

colorscheme molokai
" Better gitcommit messages
hi diffAdded   ctermbg=NONE ctermfg=46  cterm=NONE guibg=NONE guifg=#00FF00 gui=NONE
hi diffRemoved ctermbg=NONE ctermfg=196 cterm=NONE guibg=NONE guifg=#FF0000 gui=NONE
hi link diffLine String
hi link diffSubname Normal

And here we have a before / after :)

Before / after

Further information

It is possible to remap F10 to *show me what syntax is this*. Then, one can modify what s/he feels needs some adjustments, as I've done for the 'strong' diffLine and to the 'green' diffSubname.

  • Why don't you simply edit the colorscheme itself? – romainl Sep 27 '15 at 11:07
  • I did it, as did the first user in the issue, but with no results. It's like the colorscheme overwrites the Diff*... (On the first line I've linked the issue.) – Atcold Sep 27 '15 at 11:08
  • I'm confused. Why are there `\` at the start of each line? – muru Sep 27 '15 at 11:38
  • @muru, :help new-line-continuation. – romainl Sep 27 '15 at 11:43
  • @romainl wow. That is horribly counter-intuitive when compared to other languages. – muru Sep 27 '15 at 11:45
6

DiffAdd and DiffDelete are only used when actually performing a diff ($ vim -d foo.txt bar.txt, $ vimdiff foo.txt bar.txt, $ git mergetool, etc.); those highlight groups are totally irrelevant, here.

The highlight groups used for added and deleted lines when reading a diff file are diffAdded and diffRemoved.

Adding the lines below between line 272 and line 274 of molokai.vim should fix your problem:

hi diffAdded   ctermbg=NONE ctermfg=108 cterm=NONE guibg=NONE guifg=#87af87 gui=NONE
hi diffRemoved ctermbg=NONE ctermfg=131 cterm=NONE guibg=NONE guifg=#af5f5f gui=NONE

(Those are the colors used in my own colorscheme, use the ones you want.)

  • 1
    Wow!!! It did work! Where did you get the two commands diffAdded and diffRemoved? Let's say I'd like to change the bright green used after the @@ with the theme's orange, how would I find that? – Atcold Sep 27 '15 at 11:53
  • 1
    OK, found it here. Now I'm in control! Uhahaha! – Atcold Sep 27 '15 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.