27

Adding the following to .vimrc works

:hi Folded ctermbg=Grey

but it's still too bright and prominent, so we want to specify a more specific color triplet instead, like so:

:hi Folded ctermbg=#A0A0A0

but vi won't accept it:

Error detected while processing /home/guest/.vimrc:
line   10:
E421: Color name or number not recognized: ctermbg=#A0A0A0

Any suggestions?

silvernightstar
  • 1,745
  • 3
  • 17
  • 23

2 Answers2

53

The cterm in ctermbg is short for "color terminal". It is used to define the background color when Vim runs in a terminal emulator and can only accept named colors like grey or cyan or color numbers like 7. Hexadecimal values only work in GVim/MacVim and must be used with guibg/guifg like that:

hi Folded guibg=#A0A0A0

In your shell, do $ echo $TERM: it should return something like xterm, screen, xterm-256color or some variants.

If you run Vim in a terminal emulator that can't display more than 8/16 colors ($TERM doesn't contain 256color), you won't be able to use a different shade of grey unless you define your own palette in your terminal emulator.

It should look like this:

hi Folded ctermbg=7

or like that:

hi Folded ctermbg=grey

If your terminal emulator advertises itself as "256 colors ready" ($TERM contains 256color), you are able to use any color in this chart as long as you use its number (242) and not its hexadecimal value.

It should look like this:

hi Folded ctermbg=242
dessert
  • 190
  • 3
  • 13
romainl
  • 158,436
  • 18
  • 236
  • 264
  • echo $TERM results in "xterm", and I have PuTTY configured to use xterm 256 color mode. When I try Color 216 (Peach), it appears as black in PuTTY. Do I need to do something such that $TERM will result in xterm256 or 256color? Thanks – silvernightstar Apr 15 '13 at 12:21
  • `TERM` is defined at the terminal emulator level: if you have configured PuTTY to use `xterm-256color` and you get `xterm` then something is messing with you. – romainl Apr 15 '13 at 12:48
  • looks like xterm/xterm-256color/256color (assigned to $TERM) are just arbitrary strings that can be configured in PuTTY. Found the solution in http://www.mediabandit.co.uk/blog/151_putty-colours. Anyway thanks for the lead – silvernightstar Apr 15 '13 at 13:02
  • Is it also possible to set "no color"? I'm trying to remove visible BG from the folded line, blending it with others (highlighted line no. is enough for me). When I set 16, the color is black which does not fit every term's scheme, and 0 or not setting it results in grey. – Alois Mahdal Mar 12 '15 at 17:51
  • 3
    @AloisMahdal, `ctermbg=NONE guibg=NONE`. – romainl Mar 12 '15 at 20:38
0

In addition to romainl's explanation, the following lines must be added to .vimrc as described here:

if &term =~ "xterm"
  "256 color --
  let &t_Co=256
  " restore screen after quitting
  set t_ti=ESC7ESC[rESC[?47h t_te=ESC[?47lESC8
  if has("terminfo")
    let &t_Sf="\ESC[3%p1%dm"
    let &t_Sb="\ESC[4%p1%dm"
  else
    let &t_Sf="\ESC[3%dm"
    let &t_Sb="\ESC[4%dm"
  endif
endif

After which any decimal color value chosen from the xterm256 color table provided by romainl should display in PuTTY accordingly.

Community
  • 1
  • 1
silvernightstar
  • 1,745
  • 3
  • 17
  • 23