Change syntax color in vim?

36,191

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)

Share:
36,191

Related videos on Youtube

unholysampler
Author by

unholysampler

I'm a person just like everyone else.

Updated on May 06, 2022

Comments

  • unholysampler
    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
    unholysampler over 14 years
    In this case it doesn't matter as I'm working with a headless server, but good to know in the future.
  • John Salvatier
    John Salvatier over 11 years
    This doesn't work for me for python, but it does for other files.
  • MikeKulls
    MikeKulls about 11 years
    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. :-)
  • Krista K
    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
    Ungeheuer almost 7 years
    Put this is in command-mode on Windows, nothing changed. And I tried putting into my _vimrc as well.
  • Karmavil
    Karmavil over 5 years
    Does anyone else think that the comment above is contradictory?
  • Karmavil
    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
    felwithe over 4 years
    This doesn't answer the question.
  • felwithe
    felwithe over 4 years
    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.
  • Michael Currie
    Michael Currie about 2 years
    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.