Change syntax color in vim?
Solution 1
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.
Solution 2
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.
Solution 3
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
Solution 4
$VIMRUNTIME/colors/README.txt (on my system, /usr/share/vim/vim72/colors)
Related videos on Youtube
Comments
-
unholysampler about 2 years
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?
-
unholysampler over 14 yearsIn this case it doesn't matter as I'm working with a headless server, but good to know in the future.
-
John Salvatier over 11 yearsThis doesn't work for me for python, but it does for other files.
-
MikeKulls about 11 yearsI 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. :-)
-
Krista K over 9 years+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. -
Ungeheuer almost 7 yearsPut this is in command-mode on Windows, nothing changed. And I tried putting into my
_vimrc
as well. -
Karmavil over 5 yearsDoes anyone else think that the comment above is contradictory?
-
Karmavil over 5 years@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)
-
felwithe over 4 yearsThis doesn't answer the question.
-
felwithe over 4 yearsThis 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. -
Michael Currie about 2 yearsThis 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
.