130

When I try to change the background colors in .vimrc or directly in Vim using the command:

set background=dark

... it doesn't affect my background at all. Neither does the light option. However, it looks okay when I run gvim.

Is there a way to change the background in Vim without changing my Konsole settings?

EDIT Okay, there is a difference between guifg/guibg and ctermfg/ctermbg. While the GUI accepts lots of different color combinations, cterm allows only few standard ones.

Maksim Vi.
  • 9,107
  • 12
  • 59
  • 85
  • 1
    You can get the terminal to accept a lot of those colours as well. See this page: http://vim.wikia.com/wiki/256_colors_in_vim – Matthew Apr 16 '13 at 17:52

5 Answers5

166

As vim's own help on set background says, "Setting this option does not change the background color, it tells Vim what the background color looks like. For changing the background color, see |:hi-normal|."

For example

:highlight Normal ctermfg=grey ctermbg=darkblue

will write in white on blue on your color terminal.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • Thanks, it works. I tried that option before, but it seems that not all colors work, for instance brown and yellow options don't affect my default console background at all. – Maksim Vi. Jul 13 '09 at 02:52
  • 1
    that may be b/c of what kind of terminal vim thinks you have. – rampion Jul 13 '09 at 02:57
  • Yep, setting up your terminal description properly to make vim happy can be a hassle (I remember epic past battles with early Linux, BSD and other Unix flavors -- nowadays with Mac and Ubuntu it just seems to work, more or less, even across ssh among them, and I don't have to do much vi-editing elsewhere these days). – Alex Martelli Jul 13 '09 at 03:17
  • 3
    How can I add this to my vimrc? – Marin Apr 03 '13 at 04:15
  • 6
    Also see `:help hl-NonText` for the background colour after the last line of the file. – Matthew Apr 16 '13 at 17:48
  • 2
    @Marin: put exactly the line from the example into your vimrc `:highlight Normal ctermfg=grey ctermbg=darkblue`. Sub in whatever colours you want. – Matthew Apr 16 '13 at 17:52
  • LPT: don't try to execute `.vimrc` as a shell command just put the line there and be happy – Julio Marins May 24 '16 at 03:51
  • you can omit the `ctermfg=blah` if you just want to change the background colour – JonnyRaa Feb 11 '19 at 11:43
  • Putting this in .vimrc does not work for me. – Leo Feb 19 '21 at 17:39
26

In a terminal emulator like konsole or gnome-terminal, you should to set a 256 color setting for vim.

:set  t_Co=256

After that you can to change your background.

AA.
  • 4,496
  • 31
  • 35
15

Try adding

set background=dark

to your .gvimrc too. This work well for me.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
6

Using set bg=dark with a white background can produce nearly unreadable text in some syntax highlighting schemes. Instead, you can change the overall colorscheme to something that looks good in your terminal. The colorscheme file should set the background attribute for you appropriately. Also, for more information see:

:h color
Michael Kristofik
  • 34,290
  • 15
  • 75
  • 125
  • 7
    that actually why I posted my question here. Even dark colorschemes didn't affect my default background color. – Maksim Vi. Jul 13 '09 at 03:02
2

supplement of windows

gvim version: 8.2

location of .gvimrc: %userprofile%/.gvimrc

" .gvimrc
colorscheme darkblue

Which color is allows me to choose?

Find your install directory and go to the directory of colors. in my case is: %PROGRAMFILES(X86)%\Vim\vim82\colors

blue.vim
darkblue.vim
slate.vim
...
README.txt
Carson
  • 6,105
  • 2
  • 37
  • 45