Incorrect colors with vim in iTerm2 using Solarized

MacosVimColor SchemeIterm

Macos Problem Overview


I am having a strange issue with iTerm2, in terminal vim (non-gui) and the solarized color scheme. First, I have set iTerm2 to use the dark solarized colour scheme.

I am also using solarized for vim. I have the following lines in my .vimrc

set background=dark
colorscheme solarized

In the terminal the color scheme looks incorrect: console vim

For reference this is how it looks under MacVim (gui vim) gui vim

What do I need to change in iTerm or my .vimrc to get the colors looking correctly in my console vim?

Macos Solutions


Solution 1 - Macos

A couple of things to check:

  1. In iTerm2, in Preferences -> Profiles -> Terminal, under "Terminal Emulation" you have "Report Terminal Type:" set to xterm-256color.

  2. In your .vimrc, there are some options you can also set to make sure it's using 256 colors:

    set background=dark
    " solarized options
    let g:solarized_visibility = "high"
    let g:solarized_contrast = "high"
    colorscheme solarized
    
    And one of those should work, but #1 first.

BUT, if you're using the default, built in vim on Snow Leopard, it won't work, as it's not built with support for 256 colors. I believe the built in version in Lion does.

Edit: Based on several comments on this answer, I've removed let g:solarized_termcolors = 256 line from the .vimrc example above. It appears that could be a problem for some. Another says that adding the line let g:solarized_termcolors = 16 fixed a color display problem. Your own mileage may vary.

Second Edit: If you've loaded the solarized color palette into iTerm2, then you must let g:solarized_termcolors=16. Only let g:solarized_termcolors=256 if you are not using the solarized palette as your iTerm2 color preset.

Solution 2 - Macos

The above answers didn't work for me.

I'm using iTerm2 with vim 7.3 on OS X 10.7.4.

If the above solutions didn't work for you too, try this

syntax on
set background=dark
let g:solarized_termtrans = 1
colorscheme solarized

Update: According to Jim Stewart, this works on Kitty too.

Solution 3 - Macos

https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized

Download Solarized package (https://github.com/altercation/solarized) and follow instructions:

> Open iTerm 2, open Preferences, click on the "Profiles" (formerly Addresses, formerly Bookmarks) icon in the preferences toolbar, then select the "colors" tab. Click on the "load presets" and select "import...". Select the Solarized Light or Dark theme file. > > You have now loaded the Solarized color presets into iTerm 2, but > haven't yet applied them. To apply them, simply select an existing > profile from the profile list window on the left, or create a new > profile. Then select the Solarized Dark or Solarized Light preset from > the "Load Presets" drop down.

====================================

Or:

cd ~/.vim/bundle
git clone git://github.com/altercation/vim-colors-solarized.git

Modify .vimrc

Dark Theme:

syntax enable
set background=dark
colorscheme solarized

Light

syntax enable
set background=light
colorscheme solarized

Solution 4 - Macos

This worked for me in OS X 10.9.1 in iTerm 2 as well as Terminal. One mistake I was making was putting the colorscheme declaration before the termtrans and termcolors settings (and I needed both of these to make it work). As others have said, I set my terminal type to xterm-256color

if !has("gui_running")
    let g:solarized_termtrans=1
    let g:solarized_termcolors=256
endif

colorscheme solarized
set background=dark

Solution 5 - Macos

I struggled with the same problem on OSX 10.11.6, iTerm2 Build 3.0.12.

Here is my fix for it.

.vimrc

syntax enable
set background=dark
colorscheme solarized

2. Set Report Terminal Type to xterm-256color.

enter image description here

  1. Set color preset in the profile to Solarized Dark

enter image description here

Solution 6 - Macos

From the creator: http://ethanschoonover.com/solarized/vim-colors-solarized

>IMPORTANT NOTE FOR TERMINAL USERS: > >If you are going to use Solarized in Terminal mode (i.e. not in a GUI version like gvim or macvim), please please please consider setting your terminal emulator’s colorscheme to used the Solarized palette. I’ve included palettes for some popular terminal emulator as well as Xdefaults in the official Solarized download available from Solarized homepage. If you use Solarized without these colors, Solarized will need to be told to degrade its colorscheme to a set compatible with the limited 256 terminal palette (whereas by using the terminal’s 16 ansi color values, you can set the correct, specific values for the Solarized palette). > >If you do use the custom terminal colors, solarized.vim should work out of the box for you. If you are using a terminal emulator that supports 256 colors and don’t want to use the custom Solarized terminal colors, you will need to use the degraded 256 colorscheme. To do so, simply add the following line before the colorschem solarized line:

let g:solarized_termcolors=256

>Again, I recommend just changing your terminal colors to Solarized values either manually or via one of the many terminal schemes available for import.

Solution 7 - Macos

Bill Turner's answer works, but there is a way to get the colors to match MacVim exactly. Solarized has support specifically for iTerm2, among other terminal emulators.

  1. Go to the [iterm2-colors-solarized github page][1]
  2. Follow the instructions under "Installation"
  3. Make sure your .vimrc has the line colorscheme solarized

This should set the vim colors in iTerm2 to be exactly as they are in gui editors.

[1]: https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized "the iterm2-colors-solarized github page"

Solution 8 - Macos

A simple way to solve this problem is:

In colors dir on vim-color-solarized exist an arquive named 'solarozed.vim'

Open this file and search:
exe "let s:bg_back = ' ".s:vmode."bg=".s:back ."'"

replace to:
exe "let s:bg_back = ' ".s:vmode."bg=".s:none ."'"

Solution 9 - Macos

For any still having issues like I was, I had installed iterm2 solarized color profile. Installing vim-color-solarized to vim bundles and following the instructions was unnecessary and was incompatible. There were funny highlighting issues like in the screen capture above.

Lesson learned: don't do both.

Solution 10 - Macos

I tried all of the previous suggestions. I just added set t_Co=256 to .vimrc and it was fixed. I didn't need to create a tmux alias or change my config file.

Solution 11 - Macos

None of the previous answers worked for me. Apparently I was missing:

set termguicolors

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZameer ManjiView Question on Stackoverflow
Solution 1 - MacosBill TurnerView Answer on Stackoverflow
Solution 2 - MacosJason YeoView Answer on Stackoverflow
Solution 3 - Macosd.danailovView Answer on Stackoverflow
Solution 4 - MacosAmar BView Answer on Stackoverflow
Solution 5 - MacosJason KimView Answer on Stackoverflow
Solution 6 - MacosProksimaView Answer on Stackoverflow
Solution 7 - MacosWillView Answer on Stackoverflow
Solution 8 - MacosdsandradeView Answer on Stackoverflow
Solution 9 - MacosnlambertView Answer on Stackoverflow
Solution 10 - MacosMikeView Answer on Stackoverflow
Solution 11 - MacosCory KleinView Answer on Stackoverflow