I have a clean installed mac, running OS X 10.11.4.
I have installed iTerm 2, and set it up to use oh-my-zsh.

I'm trying to set up a theme for my iTerm. I am trying to use the avit theme.

It's supposed to look like this: enter image description here

But what I get is:

enter image description here

Vim is also hurt by this, i expect:

enter image description here

What I get:

enter image description here

Here's my preferences:

enter image description here

I have played around with the Report Terminal Type, but this is the one working the best, as the others are even more off.

My .zshrc looks like this: http://pastebin.com/ixe72yjP
Note the pastebin says kardan theme, however, it doesn't work with any theme

It seems like the colors of iTerm is overwriting the colors defined in the themes. Is this expected behavior?

  • The RGB values of the the first 8 or 16 colors (which are often used because they do not depend on the 256color extension) depend on the terminal emulator and are often configurable. Have a look at the tab "Colors" of the "Preferences" Dialog. – Adaephon Apr 4 '16 at 14:24
  • Just saw your edit. Yes that is expected. Inside (most?) terminals themes cannot set colors by their RGB value, but use the color index instead. Depending on the terminal 8, 16, 88 or 256 colors are available. While most terminals support 256 colors and indices 16 to 255 seem to be the same for most terminals, many themes only use 0-15 (shell more so than vim). It is more portable and users can change colors to their liking in their terminal without changing every theme (vim, dircolors, shell, etc…) – Adaephon Apr 4 '16 at 14:38
  • @Adaephon So really, an iTerm theme is just how it behaves, and I'll have to fit the colors in as i wish, to make it look like the theme I want? – Kao Apr 4 '16 at 14:49
  • You got the gist of it. Although "iTerm theme" would refer to the color settings in the terminal emulator, while "avit" and "kardan" would be zsh themes (oh-my-zsh themes to be precise). See my answer for a, hopefully, better explanation. – Adaephon Apr 4 '16 at 20:39

There are two layers of settings/themes at work here:

  • The terminal or terminal emulator, in your case iTerm2

    Depending on the terminal only a limited color palette is supported. "Traditionally" there have been 16 colors: 8 Normal and 8 Light/Bright. They are assigned the code 0 to 7 and 8 to 15, respectively. They also have names, with the codes n and n+8 sharing the same name:

    • 0 and 8: black
    • 1 and 9: red
    • 2 and 10: green
    • 3 and 11: yellow
    • 4 and 12: blue
    • 5 and 13: magenta
    • 6 and 14: cyan
    • 7 and 15: white

    While the names are well defined, the exact color values are not and vary greatly even in the default settings for different terminals. (For examples have a look at the Colors section on the Wikipedia page on ANSI escape code). Most terminal emulators allow for these 16 colors to be freely configured by the user (Have a look at the Colors tab in the iTerm preferences).

    Many (if not most) modern terminal emulators support a 256 color palette, which consists of the 16 colors mentioned above, 216 colors on a 6x6x6 RGB color cube and 32 grayscale colors. Aside from the first 16 colors these colors seem to be the same for most terminal emulators (See my answer on a question regarding this on SO for more details).

    There is even growing support for 24bit true color. According to this Gist iTerm2 already supports this in the beta builds. (You can check this with for a in {0..255}; printf "\x1b[48;2;255;${a};0m \x1b[0m". It should print a smooth gradient from red to yellow.)

    In short: A terminal (iTerm2) theme is only color palette which maps indices to true color RGB values. Some terminals (at least on Linux; I do not know about OS X and iTerm2 in particular) actually implement switchable color themes.

  • The shell or application, in your case zsh with oh-my-zsh configuration framework and vim:

    As 24bit true color is not yet widely supported, themes usually set colors by the index number on the terminal palette or even by name. For example

    print -P '%F{yellow}yellow %F{2}green %1Fred %F{117}light blue' 

    print -P interprets the string like it would be in the prompt. %F changes the foreground color.

    Although most terminals support 256 colors there are still quite a few themes that only utilize (the first) 16 colors. There are several reasons for that:

    • It will work "everywhere" (older machines, misconfigured terminals).
    • For most terminal emulators, the colors can be easily modified to taste by the user.
    • Some themes may even predate the wide availability of 256-color terminals.

    That is not to say that there are no themes that utilize 256 colors, on the contrary. I just seems that the one you chose is not one of them.

    In short: A terminal (or application) theme can only assign to color codes not true color RGB values. The actual colors depend on the terminal settings. If the color is changed in the terminal, it affects all applications running in it.

So the difference between the screenshots of the expected result and what you actually get is due the difference in the color settings of the terminals. To solve this you can:

  • modify the iTerm2 settings to fit the colors on the screenshots
  • use another theme, which makes only use of the colors 16-256 (which are largely fixed)
  • use true color enabled software (e.g. iTerm2 beta (it may soon be in the release version, if not already) and neovim) and themes (neovim seems to use the GUI settings when true color is enabled). the Gist mentioned above has a list.
  • 1
    What a thorough answer. Thank you so much! – donut Aug 22 '17 at 20:26
  • I still see this problem, not in vim but in zsh. Surely we no longer need a beta version of iTerm2? – Thomas Ahle May 15 '18 at 13:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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