在哪里可以找到默认配色方案的 *.vim文件

7d7tgy0s  于 2023-04-06  发布在  其他
关注(0)|答案(3)|浏览(141)

在浏览了几十种配色方案之后,我真的找不到比“默认”vim配色方案更好的了。
我想把它稍微扭曲一下,但找不到方案文件,这样的文件存在吗?或者有一种方法可以将当前的方案保存到一个文件中并编辑它?

b5buobof

b5buobof1#

$VIMRUNTIME/colors/default.vim

不会对你有多大帮助,因为它没有为一个高亮组定义一个视觉属性。
某些高光组使用“特殊”语法定义其视觉属性:

$VIMRUNTIME/syntax/syncolor.vim

以下是它的要点(截至2023年4月):

if &background == "dark"
  SynColor Comment  term=bold cterm=NONE ctermfg=Cyan ctermbg=NONE gui=NONE guifg=#80a0ff guibg=NONE
  SynColor Constant term=underline cterm=NONE ctermfg=Magenta ctermbg=NONE gui=NONE guifg=#ffa0a0 guibg=NONE
  SynColor Special  term=bold cterm=NONE ctermfg=LightRed ctermbg=NONE gui=NONE guifg=Orange guibg=NONE
  SynColor Identifier   term=underline cterm=bold ctermfg=Cyan ctermbg=NONE gui=NONE guifg=#40ffff guibg=NONE
  SynColor Statement    term=bold cterm=NONE ctermfg=Yellow ctermbg=NONE gui=bold guifg=#ffff60 guibg=NONE
  SynColor PreProc  term=underline cterm=NONE ctermfg=LightBlue ctermbg=NONE gui=NONE guifg=#ff80ff guibg=NONE
  SynColor Type     term=underline cterm=NONE ctermfg=LightGreen ctermbg=NONE gui=bold guifg=#60ff60 guibg=NONE
  SynColor Underlined   term=underline cterm=underline ctermfg=LightBlue gui=underline guifg=#80a0ff
  SynColor Ignore   term=NONE cterm=NONE ctermfg=black ctermbg=NONE gui=NONE guifg=bg guibg=NONE
else
  SynColor Comment  term=bold cterm=NONE ctermfg=DarkBlue ctermbg=NONE gui=NONE guifg=Blue guibg=NONE
  SynColor Constant term=underline cterm=NONE ctermfg=DarkRed ctermbg=NONE gui=NONE guifg=Magenta guibg=NONE
  " #6a5acd is SlateBlue
  SynColor Special  term=bold cterm=NONE ctermfg=DarkMagenta ctermbg=NONE gui=NONE guifg=#6a5acd guibg=NONE
  SynColor Identifier   term=underline cterm=NONE ctermfg=DarkCyan ctermbg=NONE gui=NONE guifg=DarkCyan guibg=NONE
  SynColor Statement    term=bold cterm=NONE ctermfg=Brown ctermbg=NONE gui=bold guifg=Brown guibg=NONE
  " #6a0dad is Purple
  SynColor PreProc  term=underline cterm=NONE ctermfg=DarkMagenta ctermbg=NONE gui=NONE guifg=#6a0dad guibg=NONE
  SynColor Type     term=underline cterm=NONE ctermfg=DarkGreen ctermbg=NONE gui=bold guifg=SeaGreen guibg=NONE
  SynColor Underlined   term=underline cterm=underline ctermfg=DarkMagenta gui=underline guifg=SlateBlue
  SynColor Ignore   term=NONE cterm=NONE ctermfg=white ctermbg=NONE gui=NONE guifg=bg guibg=NONE
endif
SynColor Error      term=reverse cterm=NONE ctermfg=White ctermbg=Red gui=NONE guifg=White guibg=Red
SynColor Todo       term=standout cterm=NONE ctermfg=Black ctermbg=Yellow gui=NONE guifg=Blue guibg=Yellow

该块后面是另一个块,该块将许多常见高光组链接到上面列出的高光组:

SynLink String      Constant
SynLink Character   Constant
SynLink Number      Constant
SynLink Boolean     Constant
SynLink Float       Number
SynLink Function    Identifier
SynLink Conditional Statement
SynLink Repeat      Statement
SynLink Label       Statement
SynLink Operator    Statement
SynLink Keyword     Statement
SynLink Exception   Statement
SynLink Include     PreProc
SynLink Define      PreProc
SynLink Macro       PreProc
SynLink PreCondit   PreProc
SynLink StorageClass    Type
SynLink Structure   Type
SynLink Typedef     Type
SynLink Tag     Special
SynLink SpecialChar Special
SynLink Delimiter   Special
SynLink SpecialComment  Special
SynLink Debug       Special

有一件事应该是显而易见的:这些突出显示组都与语法突出显示相关,即文本中与语法相关的标记。编辑器的chrome,即其UI,在这里不处理。
用于编辑器chrome的高亮组(状态行,行号,视觉选择,在diff模式下的diff颜色等)在Vim本身的src/highlight.c中处理。整个事情很长,所以这里是一个示例,截至2023年4月:

static char *(highlight_init_both[]) = {
    CENT("ErrorMsg term=standout ctermbg=DarkRed ctermfg=White",
     "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"),
    CENT("IncSearch term=reverse cterm=reverse",
     "IncSearch term=reverse cterm=reverse gui=reverse"),
    CENT("ModeMsg term=bold cterm=bold",
     "ModeMsg term=bold cterm=bold gui=bold"),
    CENT("NonText term=bold ctermfg=Blue",
     "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"),
    CENT("StatusLine term=reverse,bold cterm=reverse,bold",
     "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"),
    CENT("StatusLineNC term=reverse cterm=reverse",
     "StatusLineNC term=reverse cterm=reverse gui=reverse"),
    "default link EndOfBuffer NonText",
    CENT("VertSplit term=reverse cterm=reverse",
     "VertSplit term=reverse cterm=reverse gui=reverse"),
#ifdef FEAT_CLIPBOARD
    CENT("VisualNOS term=underline,bold cterm=underline,bold",
     "VisualNOS term=underline,bold cterm=underline,bold gui=underline,bold"),
#endif
#ifdef FEAT_DIFF
    CENT("DiffText term=reverse cterm=bold ctermbg=Red",
     "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"),
#endif
    CENT("PmenuSbar ctermbg=Grey",
     "PmenuSbar ctermbg=Grey guibg=Grey"),
    CENT("TabLineSel term=bold cterm=bold",
     "TabLineSel term=bold cterm=bold gui=bold"),
    CENT("TabLineFill term=reverse cterm=reverse",
     "TabLineFill term=reverse cterm=reverse gui=reverse"),
#ifdef FEAT_GUI
    "Cursor guibg=fg guifg=bg",
    "lCursor guibg=fg guifg=bg", // should be different, but what?
#endif
    "default link QuickFixLine Search",
    "default link CursorLineSign SignColumn",
    "default link CursorLineFold FoldColumn",
    "default link CurSearch Search",
    "default link PmenuKind Pmenu",
    "default link PmenuKindSel PmenuSel",
    "default link PmenuExtra Pmenu",
    "default link PmenuExtraSel PmenuSel",
    CENT("Normal cterm=NONE", "Normal gui=NONE"),
    NULL
};

基本上,chrome 突出显示组是Vim正常运行所必需的,它们是硬编码的,这样Vim就可以在每个场景中使用它们,而 syntax 突出显示组则不是必需的,它们作为运行时的一部分分发。
现在,从这些信息中重建一个实际的default独立配色方案并不是特别困难:你把所有这些文本块放到一个文件里,然后用你的Vim-fu把整个东西编辑成形状。但这不是必要的。
事实上,由于Vim在hi clear之后无论如何都会恢复为default,因此将几个所需的覆盖放在 backbone 配色方案文件中会更简单:

" ~/.vim/colors/mydefault.vim
hi clear
let g:colors_name = 'mydefault'

if &background ==# 'dark'
    hi ...
else
    hi ...
endif

这不需要知道默认配色方案实际使用的颜色。
vimrc中用an autocommand覆盖需要覆盖的内容会更简单。

ca1c2owp

ca1c2owp2#

这可能与系统有关,但要查看当前配色方案的名称,只需使用

:colorscheme

如果是default,可以通过locate default.vimfind / -name default.vim找到。
对我来说是在

/usr/share/vim/vim73/colors/default.vim
gk7wooem

gk7wooem3#

这就是我的default.vim文件中的内容

" Vim color file
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last Change:  2001 Jul 23

" This is the default color scheme.  It doesn't define the Normal
" highlighting, it uses whatever the colors used to be.

" Set 'background' back to the default.  The value can't always be estimated
" and is then guessed.
hi clear Normal
set bg&

" Remove all existing highlighting and set the defaults.
hi clear

" Load the syntax highlighting defaults, if it's enabled.
if exists("syntax_on")
  syntax reset
endif

let colors_name = "default"

" vim: sw=2

正如你所看到的,没有定义颜色。但是你可以看看与default.vim相同的文件夹中的其他配色方案,以了解如何定义颜色,然后你可以将它们添加到default.vim或创建自己的配色方案。
另见

:help coloring

相关问题