Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a custom color to folded highlighting in .vimrc (for use with putty)

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?

like image 750
silvernightstar Avatar asked Apr 15 '13 11:04

silvernightstar


People also ask

How do I change VI color scheme?

You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.

How do I change the default color scheme in vim?

vimrc (or . Here, you can set the default color scheme by modifying the colorscheme line and setting the theme you prefer. When manually configuring syntax highlighting, you can add individual instructions with the highlight command.

How do I turn on syntax highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.


1 Answers

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
like image 91
romainl Avatar answered Oct 19 '22 06:10

romainl