313

Mostly I edit Ruby files, although shell script file comments are also #

Currently my comments show as dark blue on black which is really hard to read.

See screenshot.

How can I change their color?

I'm willing to consider different schemas for all colors though I do like the black background as a base.

A screenshot of a terminal window with Vim running in it. The comments are dark blue on black background making them hardly visible.

  • 4
    I like a contrasting background for comments -- it sets them off from the code, eg. hi Comment ctermbg=gray ctermfg=darkblue. You can set your color scheme and then change it bit by bit; put the bits in a seperate file and source it from your vimrc at the end. – goldilocks Aug 30 '13 at 16:05
  • 3
    TL;DR Just edit ~/.vimrc and add the line colorscheme desert – intotecho Dec 07 '18 at 03:47
  • 5
    All these years later, how is this still the default? – Eric J. Feb 13 '22 at 21:43

12 Answers12

315

There are many color schemes which are usually distributed together with vim. You can select them with the :color command.

You can see the available color schemes in vim's colors folder, for example in my case:

$ ls /usr/share/vim/vimNN/colors/ # where vimNN is vim version, e.g. vim74
blue.vim  darkblue.vim  default.vim  delek.vim  desert.vim  elflord.vim 
evening.vim  koehler.vim  morning.vim  murphy.vim  pablo.vim  peachpuff.vim
README.txt  ron.vim  shine.vim  slate.vim  torte.vim  zellner.vim

I usually use desert. So I open vim, then enter :color desert and enter. To have the color scheme by default every time you open vim, add :color desert into your ~/.vimrc.

(Michael, OP) This was good. The terminal looks like:

Example of VIM on a Ruby file showing syntax highlighting in various colors

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
replay
  • 8,553
  • 1
  • 27
  • 31
  • 39
    You can also cycle through available colors with TAB after typing :color. – Daddy32 May 15 '17 at 16:06
  • In my case it was in /usr/share/vim/vim80/colors/. – Philippe Remy Sep 17 '20 at 02:17
  • 1
    Good choices that work the same on powershell/wsl/ubuntu: :colorscheme industry (medium contrast) :colorscheme elflord (hard contrast) and :colorscheme evening (soft contrast) – ndemou Nov 21 '20 at 11:15
  • Thanks @Daddy32. It showed all the schemes. For some reason I was hoping you'd get a preview of how it'd look with the schemes when you cycle through, but at least you get to see all available names. – NurShomik Jan 29 '21 at 00:56
201

As you are using a dark background in your terminal, you simply need to set

:set background=dark

instead of the default

:set background=light

The colors are then automatically correctly set.

If you want to have this permanently, add the line

set background=dark

to your $HOME/.vimrc file.

jofel
  • 26,758
  • 20
    While the accepted answer has useful information, this answer is far more concise about the root cause of the problem for folks like myself who prefer a dark themed terminal window. – Mark Edington Oct 05 '15 at 05:16
  • 10
    Unfortunately this still uses that almost unreadable dark blue in places. – rooby Mar 08 '16 at 00:32
  • 2
    @rooby Often, you can change the default colors in your terminal emulator, see also the other answers. – jofel Mar 08 '16 at 09:23
  • 4
    It seems rather strange that debian (at least) defaults to a dark background for its terminal window but the same distribution's vim defaults to a light background assumption about the terminal. – James Bowery Sep 05 '17 at 17:05
  • 3
    I think you can also just use bg instead of background – abonet Aug 03 '18 at 18:36
40

You can do it manually with this command:

:hi Comment guifg=#ABCDEF

Where ABCDEF is an appropriate color hex code.

To make it permanent, you will need to add these lines to your ~/.vimrc file (using green as an example):

syntax on
:highlight Comment ctermfg=green
terdon
  • 242,166
  • 5
    It's also possible to see your current highlight settings with :hi or :highlight (i.e. without any other arguments). – evilsoup Aug 30 '13 at 16:30
  • 2
    You can also change other types such as strings in supporting document types, example :highlight String ctermfg=green – aggregate1166877 Jun 22 '16 at 15:34
  • Editing the answer to remove the "googling" bits makes the answer appear a bit inconsistent: first, we have the use of guifg in the commandline and then, to "make it permanent" we have ctermfg. – DK Bose Jul 08 '20 at 09:22
  • Colour hex codes are easy enough to look up, but what about a link to the list of magic words (ie. "Comment" etc.)? – Ed Randall Feb 26 '21 at 12:19
  • @EdRandall you will need to use some unfortunate soul who chooses to use vim. I'm an emacs user so I can't help. – terdon Feb 26 '21 at 12:21
  • The correct element to modify depends on the type of file you are editing. For a bash script, the highlight command shows it is Special that is dark blue on black (in my current color scheme named pablo). Thus I was able to fix my current editing session with the vim command :highlight Special term=bold ctermfg=81 guifg=#00ffff. The right element name (kinda like a CSS class name) will be different for C++ source code, etc. 0x00FFFF is Cyan. – Charlie Reitzel Mar 29 '23 at 15:40
16

One option I found was in terminal preferences (top menu, not the window).

This has profile preferences and then a color tab, e.g.

enter image description here

Changing the Palette entry 5 from Dark blue to Light Lilac helped. I finally chose xterm as the color scheme and lightened up the comment color e.g.enter image description here

  • 2
    My only question now is if whether I can now save those preferences in a file so that they are there for a new machine setup. – Michael Durrant Aug 30 '13 at 14:43
  • 2
    I use xterm, and set the blue color to something palatable to my eyes in .Xresources: "XTerm*color4: light sky blue". – holygeek Aug 31 '13 at 15:00
11

I had precisely this problem a little while ago, the solution is to place the following line in your vimrc file:

set t_Co=256

And then you might have to put the following at the end of your your ~/.profile:

#set vim terminal to 256 colors.
if [ -e /usr/share/terminfo/x/xterm-256color ]; then
    export TERM='xterm-256color'
else
    export TERM='xterm-color'
fi

and then you can set:

hi Comment      ctermfg=lightblue

in your vimrc file and then you will have light blue comments.
vimrc 256: http://vim.wikia.com/wiki/256_colors_in_vim

I also noticed the screen became somewhat prettier by setting it to 256.

john-jones
  • 1,736
7

If on a dark background in Debian, then uncommenting set background=dark in /etc/vim/vimrc helps, too.

Or, if you don't want to interfere with the package's config file, rather in (a new)
/etc/vim/vimrc.local

Jay
  • 71
  • 1
  • 1
4

Here is nice git repo with 700+ colorschemes for vim

https://github.com/flazz/vim-colorschemes

clone it to ~/.vim/

git clone https://github.com/flazz/vim-colorschemes ~/.vim/

Preview schemes in vim with

:colorscheme mrkn256

(replace mrkn256 with one of these names ls ~/.vim/colors (without the .vim extension ))

To set it permanently edit ~/.vimrc add/change

colorscheme mrkn256
Michael D.
  • 2,830
3

You can generate your own gvim colors and paste them into your vimrc. Using chrome http://www.hmi-tech.in/activities/gvim-color-scheme-interactive-generator.html Interactive Color picker to generate vim hilight colors

mosh
  • 221
  • 2
  • 4
2

Maybe too far off topic but here goes

For Windows 10 WSL (Windows Subsystem for Linux)

this worked for me (in .vimrc)

syntax on

colorscheme desert "(or whatever color scheme)

muru
  • 72,889
W8WCA
  • 59
0
echo "colorscheme elflord" >> ~/.vimrc

Then re-run. I like it, light comments.

-1

Create a file on user's home

root@ip-10-100-4-227:~# vi .vimrc

Enter below syntax in file

syntax on
colorscheme desert

Source File

root@ip-10-100-4-227:~# source .vimrc
-2
:colo desert

I use this command to highlight the comments for example ;)

Stephen Kitt
  • 434,908