gnome-terminal I have
vims default syntax highlighting color scheme + some color-tuning made in my
gnome-terminal to filter out most colors with green except red, purple and brown. Recently switching to
Catalina I found
vim has different colors on default syntax highlighting color scheme showing on
Zsh.So, I'm looking to have
vim tune any(built-in or default) color scheme in
.vimrc, so that only these four colors(green+red+brown+purple) are allowed. Can it be done?
Your terminal emulator exposes an environment variable,
$TERM, that influences what capabilities Vim thinks your terminal has. The relevant capability, here, is how much colors it can display.
The most basic terminal emulators can be expected to support 8 colors (8c), but you can have 16 colors (16c), 256 colors (256c), or even millions of colors (truec) in some recent ones.
In 8c, 16c, and 256c, terminal emulators use an indexed palette for looking up colors. In 8c, the palette has 8 indices, from 0 to 7. In 16c, it has 16 indices, from 0 to 15. Etc.
- those palettes are not standardized, so there is no guarantee that a given index will look the same everywhere,
- most terminal emulators allow customizing the lower 16 indices,
- and there are hacks for customizing the upper 240 ones anyway.
In Vim, the default colorscheme is defined with generic color names, like
Brown, which are translated into indices internally. Some of the translations are pretty stable across the spectrum:
DarkGreen is always
2 in 8c, 16c, and 256c. But some others vary wildly:
3 in 8c,
6 in 16c, and
130 in 256c.
And, as we have seen above, those
130 can be "brown" but they "can" definitely be anything but "brown".
Having a different
$TERM in those two terminal emulators is one possible reason for the discrepancies you have to deal with. If one is 16c and the other is 256c,
Brown and other colors might look quite different.
You should be able to achieve maximum control over the colors used by Vim for syntax highlighting by:
- defining the same custom palette across all your terminal emulators,
- AND making sure
$TERMis set to a value that tells Vim to act as if the terminal emulator only supported 16 colors.
With a custom palette, you decide exactly the RGB value of
With a proper
$TERM, like the fairly widely supported
xterm-16color, you force Vim to always use
Brown and so on.
Note that both things have to be done. If you only define your terminal emulator's palette without forcing Vim to use it, then some or all of your colors will be ignored. If you only make sure that Vim restricts itself to 16 colors without explicitly defining your palette, then the terminal emulator's palette will be used, which can vary from program to program and platform to platform.
Note that I wrote "maximum control", not "total control". There are many other things affecting one's perception of syntax highlighting (font design, font weight, anti-aliasing, colorspace, etc.) that would need to be tackled to achieve "total control".