当我设置配色方案时出现问题,我也尝试使用
set t_Co=256
修复,但是没有任何改变。我还尝试了不同的终端仿真器和不同的设置,但实际上什么也没有改变。我尝试了GVim,显然它可以正确处理颜色,且我有一个更加一致的行为,现在我的问题是:在使用GVim而不是Vim时我错过了什么?
我是一个新的Vim用户,所以我不知道这两个应用程序的潜力。
编辑: 例如,这就是在gnome-terminal上运行的vim中的darkblue主题的外观
![enter image description here](https://istack.dev59.com/2d5vI.webp)
set t_Co=256
之外,我没有找到其他可能影响屏幕上重现颜色数量的东西。例如,这就是深蓝色主题的外观http://i42.tinypic.com/7319xy.png。 - user2384250TERM
环境变量,例如 TERM=xterm-256color
。 - Fredrik Pihl香草色系不能对颜色数量进行假设,因此它们保守地只期望PC时代的16种基本颜色。
在256色XTerm中设置vim的颜色需要更多步骤,但结果令人满意。以下是我使用的设置。确保您的XTerm实际上是256色版本(Ubuntu默认情况下是这样)。此设置将使vim和gvim使用相同的颜色。
作为奖励,如果您已经配置了XTerm使用TrueType字体,则可以将高亮渲染为斜体——请参见白色注释(如果字体支持;我使用*faceName: Droid Sans Mono
)。
" If the xterm supports 256 colors, make sure TERM=xterm-256color.
" If it supports 256 colors but sets TERM=xterm, edit the appropriate
" resource file (~/.Xdefaults or $XAPPLRESDIR/XTerm) and add
" *termName: xterm-256color
" For mintty, select the xterm-256color TERM value in the options menu.
if &term == "xterm-256color"
" Also for Cygwin's mintty.
set t_Co=256
elseif $PROFILE_OS == "Solaris"
set t_Co=256
elseif (&term == "xterm" || &term =~ "cons") && $TTY =~ "/dev/ttyv"
" Adjust for FreeBSD syscons with ANSI colors.
set t_Co=16
map <Esc>[2~ i
map <Esc>[3~ x
map <Esc>[5~ <C-B>
map <Esc>[6~ <C-F>
colorscheme delek
elseif &term == "cygwin"
" Adjust for Cygwin in a cmd.exe window.
set t_Co=16
colorscheme koehler
endif
"
" The cterm color numbers refer to XTerm colors in 256 color mode.
" Map rgb to cterm colors using <URL:https://gist.github.com/719710>.
" cterm=underline is rendered as italic with xterm +ulit
" gui=NONE turns off bold, italic.
"
" Normal must be set before colors "fg" and "bg" can be used.
highlight Normal ctermfg=216 ctermbg=233 guifg=#ffaf87 guibg=#121212
" pink C 'c'
highlight Character
\ cterm=NONE ctermfg=211 ctermbg=bg
\ gui=NONE guifg=#ff87af guibg=bg
" gray This comment.
highlight Comment
\ cterm=underline ctermfg=250 ctermbg=bg
\ gui=italic guifg=#bcbcbc guibg=bg
highlight ColorColumn cterm=NONE ctermfg=7 ctermbg=99 gui=NONE guifg=#c0c0c0 guibg=#875fff
" blue if/then/else/fi.
highlight Conditional
\ cterm=NONE ctermfg=27 ctermbg=bg
\ gui=NONE guifg=#005fff guibg=bg
" lightgreen Numbers and quoted strings.
highlight Constant
\ cterm=NONE ctermfg=82 ctermbg=bg
\ gui=NONE guifg=#5fff00 guibg=bg
highlight Cursor
\ cterm=NONE ctermfg=black ctermbg=red
\ gui=NONE guifg=black guibg=red
highlight CursorColumn cterm=NONE ctermfg=7 ctermbg=97 gui=NONE guifg=#c0c0c0 guibg=#875faf
highlight DiffAdd cterm=NONE ctermfg=8 ctermbg=24 gui=NONE guifg=#808080 guibg=#005f5f
highlight DiffChange cterm=NONE ctermfg=8 ctermbg=56 gui=NONE guifg=#808080 guibg=#5f00d7
highlight DiffDelete cterm=NONE ctermfg=8 ctermbg=88 gui=NONE guifg=#808080 guibg=#870000
highlight DiffText cterm=NONE ctermfg=8 ctermbg=90 gui=NONE guifg=#808080 guibg=#870087
" Status line.
highlight Error
\ cterm=NONE ctermfg=196 ctermbg=234
\ gui=NONE guifg=#ff0000 guibg=black
highlight ErrorMsg
\ cterm=NONE ctermfg=172 ctermbg=black
\ gui=NONE guifg=orange guibg=black
highlight Folded
\ cterm=NONE ctermfg=112 ctermbg=235
\ gui=NONE guifg=#87d700 guibg=#262626
highlight FoldColumn
\ cterm=NONE ctermfg=112 ctermbg=235
\ gui=NONE guifg=#87d700 guibg=#262626
" green Function names (has()).
highlight Function
\ cterm=NONE ctermfg=46 ctermbg=bg
\ gui=NONE guifg=#00ff00 guibg=bg
" lightyellow Names.
highlight Identifier
\ cterm=NONE ctermfg=139 ctermbg=bg
\ gui=NONE guifg=#af87af guibg=bg
highlight Include
\ cterm=NONE ctermfg=50 ctermbg=bg
\ gui=NONE guifg=#00ffd7 guibg=bg
highlight LineNr
\ cterm=underline ctermfg=244 ctermbg=237
\ gui=italic guifg=#808080 guibg=#3a3a3a
highlight Macro
\ cterm=NONE ctermfg=203 ctermbg=bg
\ gui=NONE guifg=#ff5f5f guibg=bg
" --More--
highlight MoreMsg
\ cterm=NONE ctermfg=123 ctermbg=238
\ gui=NONE guifg=#87ffff guibg=#444444
" --INSERT--
highlight ModeMsg
\ cterm=NONE ctermfg=123 ctermbg=238
\ gui=NONE guifg=#87ffff guibg=#444444
" Tilde and @ at the end of the window.
highlight NonText
\ cterm=bold ctermfg=cyan ctermbg=bg
\ gui=bold guifg=cyan guibg=bg
highlight Operator
\ cterm=NONE ctermfg=129 ctermbg=bg
\ gui=NONE guifg=#af00ff guibg=bg
highlight PmenuSbar cterm=NONE ctermfg=fg ctermbg=32 gui=NONE guifg=fg guibg=#0087d7
" medium blue #if/#else/#endif ${foo}
highlight PreProc
\ cterm=NONE ctermfg=75 ctermbg=bg
\ gui=NONE guifg=#5fafff guibg=bg
" Hit-enter and yes/no questions.
highlight Question
\ cterm=NONE ctermfg=green ctermbg=bg
\ gui=NONE guifg=green guibg=bg
highlight Search
\ cterm=NONE ctermfg=153 ctermbg=237
\ gui=NONE guifg=cyan guibg=gray10
" violett <F11>, printf %s, `cmd`
highlight Special
\ cterm=bold ctermfg=125 ctermbg=bg
\ gui=bold guifg=#af005f guibg=bg
" violett <F11> in map
highlight SpecialKey
\ cterm=NONE ctermfg=135 ctermbg=bg
\ gui=NONE guifg=#af5fff guibg=bg
highlight SpellBad
\ cterm=NONE ctermfg=88 ctermbg=140
\ gui=NONE guifg=#870000 guibg=#af87d7
highlight SpellCap
\ cterm=NONE ctermfg=88 ctermbg=138
\ gui=NONE guifg=#870000 guibg=#af8787
highlight SpellLocal
\ cterm=NONE ctermfg=118 ctermbg=236
\ gui=NONE guifg=#87ff00 guibg=#303030
highlight SpellRare
\ cterm=NONE ctermfg=19 ctermbg=75
\ gui=NONE guifg=#0000af guibg=#5fafff
" lightblue Keywords (highlight).
highlight Statement
\ cterm=NONE ctermfg=44 ctermbg=bg
\ gui=NONE guifg=#00d7d7 guibg=bg
highlight StatusLine
\ cterm=bold ctermfg=41 ctermbg=239
\ gui=bold guifg=#00d75f guibg=#4e4e4e
highlight StatusLineNC
\ cterm=NONE ctermfg=245 ctermbg=239
\ gui=NONE guifg=#8a8a8a guibg=#4e4e4e
" olive static, const, volatile
highlight StorageClass
\ cterm=NONE ctermfg=98 ctermbg=bg
\ gui=NONE guifg=#875fd7 guibg=bg
" green ''foo''
highlight String
\ cterm=NONE ctermfg=35 ctermbg=bg
\ gui=NONE guifg=#00af5f guibg=bg
" titles for output from ":set all", ":autocmd" etc.
highlight Title
\ cterm=NONE ctermfg=123 ctermbg=238
\ gui=NONE guifg=#87ffff guibg=#444444
" TODO XXX
highlight Todo
\ cterm=bold ctermfg=161 ctermbg=181
\ gui=bold guifg=#d7005f guibg=#d7afaf
" lightbeige int, long, ... ctermfg
highlight Type
\ cterm=NONE ctermfg=170 ctermbg=bg
\ gui=NONE guifg=#d75fd7 guibg=bg
" gray Visual selection
highlight Visual
\ cterm=NONE ctermfg=215 ctermbg=238
\ gui=NONE guifg=burlywood guibg=gray30
" gray Visual selection
highlight VisualNOS
\ ctermfg=215 ctermbg=238 ctermbg=bg
\ gui=NONE guifg=#5090c0 guibg=gray30
highlight WarningMsg
\ cterm=NONE ctermfg=green ctermbg=black
\ gui=NONE guifg=green guibg=black
highlight WildMenu
\ cterm=NONE ctermfg=23 ctermbg=148
\ gui=NONE guifg=#005f5f guibg=#afd700
if &term == "xterm-256color" && $DISPLAY == ""
" Cygwin mintty doesn't do italic.
highlight Comment cterm=NONE
highlight LineNr cterm=NONE
endif
在这个6x6x6的彩色立方体中,可以选择cterm颜色编号:
.vimrc
中使用以下代码,你可以隐藏所有这些并获得非常接近Vim控制台的东西。if has("gui_running")
" GUI is running or is about to start.
" Maximize gvim window.
set lines=120 columns=140
" Display or hide menu when using gVim
function! ToggleGUICruft()
if &guioptions=='i'
exec('set guioptions=imTrL')
else
exec('set guioptions=i')
endif
endfunction
map <F11> <Esc>:call ToggleGUICruft()<cr>
" by default, hide gui menus
set guioptions=i
endif
你现在可以使用F11键来切换菜单和滚动条。
到目前为止,我还没有发现GVim的任何缺点。如果你是新用户,菜单实际上可以帮助你发现新的命令。
:make
,但这个命令是可用的。然而,我不知道使用 Gvim 而不是终端的限制。 - Xavier T.:help gui-shell
中有所描述,但仍然含糊不清。 - Xavier T.GVim不仅是一个带有GUI和更好的颜色支持的Vim,两者之间在使用上没有太大区别。
set t_Co=256
并不是任何配色问题的正确解决方案。如果你想在Vim中使用丰富多彩的配色方案,唯一需要做的就是设置终端仿真器以使其宣传自己“能够显示256种颜色”。如何设置取决于您的终端仿真器,但通常可以将TERM
环境变量设置为xterm-256color
或类似值。您不需要做其他任何事情。
有成千上万个Vim配色方案可供选择,其中一些仅适用于GUI,另一些则仅适用于终端...确保您选择适合自己使用的配色方案。GUI配色方案可以使用数千种颜色,但CLI配色方案仅限于Xterm 256种颜色调色板;这往往使GUI配色方案“漂亮”,但不一定更实用。
如果颜色方案的名称或其README
/描述中没有提示,您可以打开它并查找guibg
和ctermbg
。如果您有ctermbg
(或ctermfg
...),则该颜色方案基本上保证可以在256色可用的终端仿真器中工作。如果您有guibg
,则该颜色方案将在GVim中工作。如果两者都有,则可以在Vim和GVim中使用相同的颜色方案。
当然,YMMV。
此外,请参见我的另一个回答,类似的问题。
xterm-256color
也不起作用,而我在使用这个“技巧”之前就看了这个答案http://askubuntu.com/questions/67/how-do-i-enable-full-color-support-in-terminal。 - user2384250好的,显然我尝试过的任何终端仿真器(xterm、gnome-terminal等)都能够管理8或256种颜色,这取决于X11设置、VGA驱动程序以及环境变量TERM
的值。因此,最佳选择是256种颜色,如果你正在寻找更好的东西,那么你别无选择,只能选择gvim
作为你的编辑器。
darkblue
,我还尝试了一些来自http://vimcolorschemetest.googlecode.com/svn/html/index-c.html的方案,但结果相同。问题在于似乎没有任何颜色方案能够正常工作。 - user2384250