changing the color of comments in vim

5

3

I use vim to browse the source code. In java source files comments appear in blue color on black background which is difficult to read, how to change this color scheme so that comments can appear in somewhat brighter color.

Suresh

Posted 2010-12-20T11:59:14.813

Reputation: 453

Answers

1

Create your own colour scheme. The easiest way to do this is to copy an existing one and tweak the line that specifies the colour. For most colour schemes, this will typically look something like this:

hi Comment  guifg=#80a0ff ctermfg=darkred

Simply change this to whatever colour you want. If you're using the default colour scheme, you could simply make a new one called (e.g.) ~/.vim/colors/suresh.vim (the path will need to be different if you're on Windows - see :help rtp) with contents like this:

hi clear
if exists("syntax_on")
    syntax reset
endif

let colors_name = "suresh"

hi Comment  guifg=#80a0ff ctermfg=darkred

I've created a colour scheme that uses a slightly different declaration format to make it a bit easier to edit (the standard one gets a bit difficult to maintain with a lot of colours and support for light and dark backgrounds). This is available here if you're interested. This self highlights, so it's easy to make a change, enter :w and see the colour that will actually be highlighted. However, if you just want to change one colour, it may be easier to just stick to the examples above.

Al.

Posted 2010-12-20T11:59:14.813

Reputation: 2 396

1It's not really necessary to create a full color shceme of your own. I just use the syncolor file that is always sourced by Vim. See ":help syncolor". – Heptite – 2010-12-20T18:59:54.013

6

Adding this to ~/.vimrc makes the blue a tad brighter (and readable) in my black-backgrounded terminals thus far:

hi comment ctermfg=blue

(Had the same "can't read blue-on-black probs described in original post until employing above. Simple to operationalize when continually working in new accounts/machines like I do. This answer may be more robust for "proper" account setup, but changes the comment to color to red, and seems to require more work to employ.)

Johnny Utahh

Posted 2010-12-20T11:59:14.813

Reputation: 503

Thanks. "hi Comment ctermfg=red" works for me to make it red. – user77830 – 2011-12-15T04:52:28.747

2

The Ubuntu terminal has a dark purple background by default, and comments in Vim are basically unreadable.

Using the following setting, either in ~/.vimrc or directly in vim (after pressing the : key) sorted out the problem for me:

set background=dark

Drew Noakes

Posted 2010-12-20T11:59:14.813

Reputation: 1 907