Change font color for comments in vim

Tag: vim , syntax-highlighting , vimrc Author: dfdsf Date: 2011-04-13

I'd like to change the default font color for comments which is dark blue to slightly yellow color. It is difficult to read on the black background. Could you advise me how to change only this one color? I'm satisfied with the other colors.

I'm using xfce4-terminal (not gvim with GUI).

So far, I have done the settings in ~/.profile file according to this link as follows

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


set t_Co=256

in ~/.vimrc

thank you

Best Answer

: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.


Thank you. ctermfg works with colors like green or yellow. But if I will give it #ABCDEF or ABCDEF it writes error E421: color name or number not recognized . It doesn't recognize letters in hexadecimal code, it recognizes only numbers.
yes, the guifg parameter is for when you use vim gui (gvim).
That means that I'm restricted to only 16 colors? I added the setting to .vimrc but this doesn't work set highlight Comment ctermfg=yellow
@xral: your terminal has a limited number of colors. If you want to stay in the terminal then only the colors available in your terminal are available in vim, typically this is 16.
There are more than 16. See here. I want to achieve that my comments are yellow but only slightly yellow and forever. Is it possible to set this in .vimrc?

Other Answer1

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.


This is an awesome solution. Maybe not the best answer to the question above, but solved the "very difficult to read" proble ina perfect way.
This should be the default on Ubuntu. Comments are basically impossible to read when dark blue on the purple background. Thanks. I included this in my ~/.vimrc file. If someone wants to test what this looks like without doing that, just type the above command into vim after pressing the : key.
That was the first thing a google search turned up. However, I like the default colors (other than comments) which work well both in the dark terminal window and when pasted into an email/doc with a white background. I like a dark terminal, what can I say? (nostalgia/custom)
adding the line 'set background=dark' to ~/.vimrc did the trick. my eyes got so use to the other colour scheme, my brain thinks this looks ugly... but at least i can see my comments now. Thanks.

Other Answer2

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.


you read my mind with the light blue :) +1

Other Answer3

syntax highlighting in vim

set background=dark


set bg=dark

best solution for VIM users!

Other Answer4

While the 'background=dark'/'set bg=dark' attribute generally solves the immediate problem of dark blue comments on a black background, it was selected by an Engineer! Duhhhh! For the time I've been using vim, I've continued using the 'out of the box' "choice", just because the color selection combo sucks soooo much less! ;^) For the time that vim has been working, there continues to still be only 2 color choice selections (set 'background=light' doesn't seem to do anything on a xfce4-terminal)? What about 'slightlydark' or 'slightlylight'? How about working at 'sundown' or 'ambulanceride'? How about using the color light green, instead of light blue? Bold light blue with light blue, is really barely different.

Other Answer5

After a bit searching one can find a decent reference to vim, regarding this issue especially, over at A decent place to get started though, is via: be :verbose hi when actually inside vim, and editing a file. Then check out how all of the variables have had metadata associated with them. Data returned from there, make 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 tormented by the light blue, as a consequence:

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