Search code examples
vimterminalzshcolor-scheme

color schemes interaction in terminal, zsh, and vim


I noticed that the color-scheme setting in .zshrc does not affect the background color of the terminal window, so I decided to load a separate preset color-scheme for the OSX terminal. This, in return, changed how the .zshrc color-scheme looked previously. Vim also has its own color-scheme that seems to be affected by that of the OSX terminal.

I'm curious if there is any universal method to change the color-schemes of all three parties. If not, please help me understand the interactions of color-schemes in the OSX terminal, vim, and zsh


Solution

  • Terminal

    Terminal.app lets you change its default color palette in its preferences. Those colors are referenced by your shell and the programs you run in it either with standard names like "blue" or with numbers from 0 to 15. Changing your terminal emulator's palette will obviously change the look of your shell and the programs you run in it.

    ZSH

    Some zsh themes use color numbers (16-255) from the xterm palette. It is possible to alter that palette but that practice is not common and I've not heard of a zsh theme doing that (which doesn't mean it doesn't exist in the wild) so it is relatively safe to assume that those colors will be the same across terminals. Such themes should not be affected by your changes to the terminal emulator's default ANSI palette.

    Some zsh themes, on the other hand, use standard color names like "green" or "red" which correspond to the 16 ANSI colors defined in the preferences of your terminal emulator. Since you changed those colors, it is logical to expect that your zsh theme looks different.

    Vim

    Well written Vim colorschemes are usually capable to work in an 8/16 colors environment or a 256 colors environment. What set of color codes to use is determined by Vim from your terminal emulator's TERM:

    TERM               colors
    
    xterm                8
    screen               8
    xterm-256color     256
    screen-256color    256
    

    Using a 256 colors ready colorscheme in an 8/16 colors environment won't work because only the numbers 0 to 15 will be used correctly.

    Using a 256 colors ready colorscheme in a 256 colors environment will likely give a consistant experience and be immune to changes in the default ANSI palette.

    Using an 8 colors ready colorscheme will likely have the same effect whether you use a 256 colors environment or an 8/16 one. Such colorschemes depend completely on the default ANSI colors, though, so they will look differently if you change your terminal emulator's settings.

    Conclusion?

    Given the following:

    • your zsh theme only uses standard ANSI names,
    • your TERM is set to an 8/16 colors value,
    • your Vim colorscheme is 8/16 colors ready,

    you should be able to achieve a consistant look and feel across the board only by tweaking the ANSI color palette in Terminal.app's preferences.