Themes in iTerm change colours in vim


How do terminals such as iTerm handle themes?
The context of my question is this;
I have a theme set in vim and this changes the syntax highlighting in my js code. When I change the theme in iTerm the colours in vim change!
I want to have a better idea so I can control these settings rather than settling for stumbling on a combination that happens to work.
Why does changing the terminal theme change the colours in vim? How can I avoid this effect?


Vim will use the so-called “ANSI” colors set by your terminal emulator to display any color in the 0-15 range so those colors will change whenever you manipulate those “ANSI” colors. That’s the basic principle; it’s perfectly sane, and there’s nothing to do about it.

If you don’t want your Vim colors to inherit from your terminal emulator’s palette you will need to use colors outside that 0-15 range. From there, you basically have two solutions…

  1. Set your TERM to xterm-256color and choose a colorscheme designed for 256 colors.

    Properly designed “256color” colorschemes only use colors in the 16-255 range so they are immune to any change to your terminal emulator’s palette.

  2. Tell Vim to use “GUI” colors in the terminal with set termguicolors and choose a nice colorscheme designed for GUI Vim.

    You will need fairly recent builds of both Vim and iTerm for this method to work so it’s not very portable but that may or may not be an issue for you.

Answered By – romainl

Answer Checked By – Terry (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.