55

I have syntax highlighting on, but comments are set to dark blue. This hard for me to read against a black terminal. How do I change it so that the comments are colored green instead?

7 Answers 7

90

Probably you just need to tell vim that you have a dark background:

:set background=dark 

This should change the highlighting to something better readable.

Sign up to request clarification or add additional context in comments.

5 Comments

In this case it doesn't matter as I'm working with a headless server, but good to know in the future.
Put this is in command-mode on Windows, nothing changed. And I tried putting into my _vimrc as well.
This doesn't answer the question.
This is a great answer but it resets every time I quit vim. So you should also add this line (without the ":") to /etc/vim/vimrc.
To make it permanent, write it to .vimrc like this: echo ':set background=dark' >> ~/.vimrc and also echo 'syntax on' >> ~/.vimrc. Comment inspired by link
16

Take a look at syncolor.vim. You'll find it in /usr/share/vim/vim{version}/syntax/.

Excerpt:

" There are two sets of defaults: for a dark and a light background. 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 

So the first SynColor line looks of interest. I confess I don't know if you can override this, as opposed to changing this file.

5 Comments

I think it is because it will affect all users. For this to work you need to change the light background version which could cause problems for users with a light background. It was the best answer for me however. :-)
+1 re-upvoted. If the downvote was for "all users" then that voter deserves a -1 on linux in general. /usr/blah-anything should immediately clue an average user that it's global.
Does anyone else think that the comment above is contradictory?
@ChrisK What is your point? ... Deducing (or not) that has effect on all users does not prevent it from having the effect. If he considers that it should be handled per user and not globally it is a perfectly valid argument. (whether or not I agree with that)
This works, but is there any way to add this to .vimrc so that it would be the proper solution? I tried but it gives me "E416: missing equal sign". I tried putting hi in front of it too, like other answers have it. Nothing wants to work though.
13

If you want to change the color of a comment without changing the background, you can use the highlight command. Vim documentation on :highlight

For example, :hi Comment term=bold ctermfg=Cyan guifg=#80a0ff gui=bold

1 Comment

This doesn't work for me for python, but it does for other files.
1

$VIMRUNTIME/colors/README.txt (on my system, /usr/share/vim/vim72/colors)

Comments

1

You can set colorsheme to desert. Default in e.g. Ubuntu 16.04

Comments

1

best way is to change colorscheme to another (lighter) one:

in navigation mode type:

:colorscheme space Ctl+D

and then type the scheme name Enter

1 Comment

This answer that actually adjusts the syntax highlighting rules. The accepted answer is insufficient to fix the dark comments. You must also set the colorscheme, as noted here.
0

For the googler's out there. https://vimdoc.sourceforge.net/htmldoc/syntax.html

You can change the highlighting per syntax file, like in javascript.vim or python.vim syntax files.

For example changing a 'Comment' to be the color green. You would add this line somewhere inside of the respective syntax file.

hi Comment term=NONE cterm=NONE ctermfg=GREEN ctermbg=NONE gui=NONE guifg=NONE guibg=NONE 

and you can do this for others like 'String'

hi String term=NONE cterm=NONE ctermfg=MAGENTA ctermbg=NONE gui=NONE guifg=NONE guibg=NONE 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.