4

I'm having a hard time understanding how the ANSI colors affect the named colors in Vim. My KiTTY terminal has "regular" and "bold" versions for the main 8 colors, plus foreground/background colors. How are these assigned to the representations of DarkGray, etc. often used to define Vim colorschemes? When I checked with :runtime syntax/colortest.vim after modifying the ANSI colors, some were changed in unexpected ways.

I'm obviously a beginner in Vim/terminal customization.

1

2 Answers 2

4

How are these assigned to the representations of DarkGray, etc. often used to define Vim colorschemes?

I can't speak for the actual design of the color schemes since that might require looking into mailing list archives to see if there were discussions about what would be good defaults.

But, in syntax.c of Vim's source code, there's a table for limited palettes in the do_highlight() function:

static char *(color_names[28]) = {
      "Black", "DarkBlue", "DarkGreen", "DarkCyan",
      "DarkRed", "DarkMagenta", "Brown", "DarkYellow",
      "Gray", "Grey",
      "LightGray", "LightGrey", "DarkGray", "DarkGrey",
      "Blue", "LightBlue", "Green", "LightGreen",
      "Cyan", "LightCyan", "Red", "LightRed", "Magenta",
      "LightMagenta", "Yellow", "LightYellow", "White", "NONE"};
static int color_numbers_16[28] = {0, 1, 2, 3,
         4, 5, 6, 6,
         7, 7,
         7, 7, 8, 8,
         9, 9, 10, 10,
         11, 11, 12, 12, 13,
         13, 14, 14, 15, -1};
/* for xterm with 88 colors... */
static int color_numbers_88[28] = {0, 4, 2, 6,
         1, 5, 32, 72,
         84, 84,
         7, 7, 82, 82,
         12, 43, 10, 61,
         14, 63, 9, 74, 13,
         75, 11, 78, 15, -1};
/* for xterm with 256 colors... */
static int color_numbers_256[28] = {0, 4, 2, 6,
         1, 5, 130, 130,
         248, 248,
         7, 7, 242, 242,
         12, 81, 10, 121,
         14, 159, 9, 224, 13,
         225, 11, 229, 15, -1};
/* for terminals with less than 16 colors... */
static int color_numbers_8[28] = {0, 4, 2, 6,
         1, 5, 3, 3,
         7, 7,
         7, 7, 0+8, 0+8,
         4+8, 4+8, 2+8, 2+8,
         6+8, 6+8, 1+8, 1+8, 5+8,
         5+8, 3+8, 3+8, 7+8, -1};

DarkGray's index is 12 in the color_names table. Assuming you have an 16 color palette, you would get the 12th item in color_numbers_16, which is color index 8. This would be the bright variant of color index 0 (8 % 8) which is bright black.

4

The sixteen so-called "ANSI" colors can be used via their index, 0 to 15 or via their semi-standard names.

From :help 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

If your terminal is limited to 8 colors, Green or LightGreen can be obtained by adding the bold attribute to 2 or DarkGreen. Note that colors 8 to 15 can only be used as foreground color in Vim.

If your terminal is capable of displaying 16 colors or more, using 10, Green, LightGreen (or any case-insensitive variant) is more or less guaranteed to look the same. Any of those 16 colors can be used by Vim for foreground and for background.

The actual RGB values used to display those colors are not standardized, though. Terminal emulators generally have their own default palettes, sometimes inherited from their GUI toolkit or from the desktop environment…

All terminal emulators allow you to change those default colors to whatever you want and most "modern" terminal emulators even let you do that via a handy GUI.

This means that there's no guarantee whatsoever that Red is going to be even remotely red-ish. Or, if you use the Windows Console, that all names and indices are mapped like in the table above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.