10

When I use the following command to set the color of my vim,

:highlight Error ctermfg=#00afff 

it prompts E421: Color name or number not recognized: ctermfg=#00afff

2 Answers 2

18

ctermfg and ctermbg use indices into the limited color palettes (8 / 16 / 88 or 256 colors) of terminals and do not support the full 24-bit RGB values.

I think you're looking for the 'termguicolors' option, which makes Vim apply the GUI color attributes to capable terminals. Colors (by name or #RGB) are specified via guifg / guibg; only cterm is used for text attributes.

2
  • Thanks again @Ingo-Karkat: you are always the one answering the question I am looking for. So thank so so much from the other side of the cable. Commented Sep 4, 2020 at 1:48
  • FWIW, I use this script with termguicolors to tweak colors for various highlighting types. Commented Apr 13, 2024 at 17:12
10

It's because :h highlight-ctermfg says:

ctermbg={color-nr} *highlight-ctermbg* The {color-nr} argument is a color number. Its range is zero to (not including) the number of tui-colors available. The actual color with this number depends on the type of terminal and its settings. [...] The following (case-insensitive) names are recognized: *cterm-colors* NR-16 NR-8 COLOR NAME ~ 0 0 Black 1 4 DarkBlue 2 2 DarkGreen 3 6 DarkCyan 4 1 DarkRed 5 5 DarkMagenta 6 3 Brown, DarkYellow 7 7 LightGray, LightGrey, Gray, Grey 8 0* DarkGray, DarkGrey 9 4* Blue, LightBlue 10 2* Green, LightGreen 11 6* Cyan, LightCyan 12 1* Red, LightRed 13 5* Magenta, LightMagenta 14 3* Yellow, LightYellow 15 7* White 

The command is not supposed to support hex color mode.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.