如何在 Vim 中更改注释的字体颜色

我想改变默认的字体颜色为评论,这是深蓝色略微黄色。在黑色的背景上很难阅读。我使用的是 xfce4终端,而不是带 GUI 的 gvim。

我怎样才能只改变这一种颜色?

到目前为止,我已经根据“ 256种颜色”更改了 ~/.profile文件中的设置,使用:

if [ -e /usr/share/terminfo/x/xterm-256color ]; then
export TERM='xterm-256color'
else
export TERM='xterm-color'
fi

还有

set t_Co=256

~/.vimrc

99430 次浏览
:hi Comment guifg=#ABCDEF

Pick your color! If using a color terminal, replace guifg=#ABCDEF with ctermfg=N with N being a color number.

Also type :help :hi for more information.

Most well-behaving colorschemes will respect the background setting.

set background=dark

would change the color of comments from dark blue to light blue, when using the default colorscheme.

See "Syntax Highlighting In VIm".

set background=dark

or

set bg=dark

are the best solution for VIM users!

hi Comment ctermfg=LightBlue

Add this to your .vimrc file which is either in your ~ or the /etc/vim directory. This will make it permanent. I haven't tested this with gvim.

I also have set background=light before I set comment color. I like all the colors it created except for the comments.

After searching you can find a decent reference to Vim regarding this issue especially, at "256 colors in vim".

Start with:

:verbose hi

when actually inside Vim, and editing a file.

Then check out how all of the variables have metadata associated with them. Data returned from there makes it real easy to add the desired modifier types into .vimrc. As an example, these are updates I recently added in order to get rid of dark blue, and not have to be tormented by the light blue:

set number background=dark
syntax on
highlight Comment    ctermfg=119
highlight Identifier ctermfg=99AA00

If the objective is to make it more readable in the dark background of the text console, the command below is a wonderful option and easy to remember:

:colorscheme evening

But be advised, it will change other element's colors.

There are various color schemes in Vim. The "default" color scheme displays comments in a blue color, which makes it hard to read against a black terminal background. I prefer to use the "desert" color scheme which displays in readable colors.

To enable the "desert" color scheme in Vim, use the command :color desert. If you want to go back to the default use :color default.

You can even update your ~/.vimrc with your preferred color scheme using:

echo 'color desert' >> ~/.vimrc

You can check your color scheme first using:

:!ls $VIMRUNTIME/colors

then try whichever suits you best.

I had the same question and wanted to edit my Comment color from LightBlue to something more toned down, and, following @Benoit's answer, this worked for me:

hi Comment ctermbg=0 ctermfg=DarkGrey
                 

I saved it in my ~/.vimrc file.

0 = Black Background, i.e. Color Terminal Background: ctermbg=0, and the Foreground text is DarkGrey, i.e. Color Terminal Foreground: ctermfg=DarkGrey.