如何自定义vimdiff颜色?


22

我正在尝试将vimdiff用作我的git合并工具,但是所使用的颜色使其难以忍受(至少在Windows / Mingw上是如此):某些冲突行的背景色和前景色是相同的,因此使其变得不必要地困难找出正在发生的事情(请参阅包含下面的行include=)。

例

Answers:


13

颜色由以下四个突出显示组(:help hl-DiffAdd)控制:

DiffAdd     diff mode: Added line
DiffChange  diff mode: Changed line
DiffDelete  diff mode: Deleted line
DiffText    diff mode: Changed text within a changed line

这些通常是由配色方案定义的,但是如果您希望整体配色,则可以~/.vimrc:colorscheme命令后(在命令之后)自定义它们,而不必突出显示差异。只需使用重新定义:highlight。这是我的个人自定义项(对于GVIM;对于终端,您需要ctermfg/bg=.../以外的其他适当属性):

hi DiffAdd      gui=none    guifg=NONE          guibg=#bada9f
hi DiffChange   gui=none    guifg=NONE          guibg=#e5d5ac
hi DiffDelete   gui=bold    guifg=#ff8080       guibg=#ffb0b0
hi DiffText     gui=none    guifg=NONE          guibg=#8cbee2

如果您要即时切换颜色方案,则需要通过以下方式重新调用这些:hi命令:autocmd ColorScheme * hi ...


11

一种快速解决方案是禁用语法突出显示。有时,代码语法高亮显示将使前景文本与vimdiff背景颜色具有相同的颜色,从而使文本“不可见”。

:syntax off

如果要为vimdiff自动执行此操作,请将其添加到您的末尾~/.vimrc

if &diff
    syntax off
endif
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.