Skip to content

On terminal emulators, colors, and typography

Romain Lafourcade edited this page Sep 23, 2022 · 2 revisions

Generalities

Color

Typography

  • Typographic attributes are defined with the attributes term= for &t_Co == 0 and cterm= for &t_Co >= 2.
  • bold, reverse and underline are widely supported so they can be used relatively safely.
  • undercurl and strikethrough are not widely supported so they shouldn't be a structural part of the colorscheme.
  • italic is theoretically widely supported but Vim can't currently detect its support in a cross-platform way so it must be used with caution.

No color: &t_Co == 0

  • Default value for XXX $TERM. (WIP)
  • cterm, ctermbg, and ctermfg are ignored.
  • Can only use typographic features (see above).

No color?: &t_Co == 2

  • Default value for XXX $TERM. (WIP)
  • When using color names, red/darkred and blue/darkblue are inverted, as well as yellow/darkyellow and cyan/darkcyan: ctermbg=darkred gives you a darkblue background and so on.
  • When using color indices, colors are in the standard "xterm" order.
  • Otherwise similar to &t_Co == 8.

8 colors: &t_Co == 8

  • Default value for xterm, xterm-color, ansi, dtterm, nsterm, rxvt, linux $TERM. (WIP)
  • When using color names for ctermbg, only the "dark" variant is used: ctermbg=red and ctermbg=darkred both work like ctermbg=darkred.
  • When using color indices for ctermbg, indices above 7 are ignored.
  • Color indices above 15 may be honored within the constraints of the terminal emulator: ctermfg=211 may work if the terminal emulator supports 256 colors. It makes more sense to target 8c explicitly than to mix indices and hope for the best.

16 colors: &t_Co == 16

  • Default value for xterm-16color $TERM. (WIP)

88 colors: &t_Co == 88

  • Default value for XXX $TERM. (WIP)

256 colors: &t_Co == 256

  • Default value for xterm-256color $TERM. (WIP)
  • Color indices 0-15 are generally user-customisable so they should be avoided.
  • Color indices 16-255 are generally safe. It is possible for the user to change them but it is a lot more involved than for indices 0-15 so users are assumed to know about their situation and asked to adjust their expectations accordingly.
  • X11/CSS Color names can be used for ctermbg and ctermfg but conversion to the 8bit color space is lossy (by definition) and poorly done by Vim anyway so color names must be avoided.
  • Vim incorrectly tries to convert the colors in g:terminal_ansi_colors. (add issue number)

True colors: has('termguicolors') && &termguicolors)

  • &t_Co is ignored.
  • If present, the values of guibg and guifg are converted for use with ctermbg and ctermfg.