Incorrect colors with vim in iTerm2 using Solarized

73,423

Solution 1

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

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

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

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

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

Here is my fix for it.

  1. .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

Share:
73,423

Related videos on Youtube

Zameer Manji
Author by

Zameer Manji

Updated on September 26, 2020

Comments

  • Zameer Manji
    Zameer Manji over 3 years

    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?

  • Sai Perchard
    Sai Perchard over 12 years
    Actually, "let g:solarized_termcolors = 256" was the cause of solarized displaying incorrectly for me. Per the git repo (github.com/vim-scripts/Solarized), "IMPORTANT NOTE FOR TERMINAL USERS:", you should "let g:solarized_termcolors=16".
  • Parker Selbert
    Parker Selbert about 12 years
    If you are using the solarized color scheme with your terminal the 16 ANSI colors will be set to the solarized colors, in which case you want to set let g:solarized_termcolors=16. If you use 256 it will be close, but the background will be grey instead of the deep sea blue.
  • styfle
    styfle over 11 years
    It seems like 256 gives me the gray background instead of dark blue on Lion but 16 looks exactly the same as omitting that variable from my vimrc. Oh well, dark gray is better than a really light gray that I was getting before.
  • Jim Stewart
    Jim Stewart over 11 years
    I'm using KiTTY (PuTTY derivative) on Windows 7, and let g:solarized_termtrans = 1 fixed an issue for me where the background color on blank lines was grey, but the background color on lines with text was black after the content.
  • Setheron
    Setheron about 11 years
    they aren't black thuogh :(
  • Achal Dave
    Achal Dave over 10 years
    If you're using any other color scheme, you can hi Normal ctermbg=NONE, since that's essentially what termtrans does in solarized (as far as I can tell from their source)
  • kravc
    kravc over 10 years
    Works for me on OSX 10.9, iTerm2 1.0.0.20131109.
  • Ian Vaughan
    Ian Vaughan over 10 years
    This is the closest to working, it sets the background colour correctly, but my cursorline, colorcolumn and line number column all have black background. Why is nothing ever easy!
  • dymv
    dymv over 10 years
  • Marten Sytema
    Marten Sytema over 10 years
    @SaiPerchard comment should be added to the answer. For me this was what fixed the wrong background color.
  • Andrew
    Andrew almost 10 years
    This worked for me as well - not sure if it makes a difference, but on OSX, I'm using tmux as well
  • Sophia Feng
    Sophia Feng over 9 years
    None of the previous answers solves my problem but this one does. It turns out that what was missing for me was the color presets.
  • user115014
    user115014 almost 9 years
    Didn't work for me: stackoverflow.com/a/12969298/1945990 did though. ITerm, solarized theme plus vim solarized theme.
  • Aaron Tribou
    Aaron Tribou over 8 years
    This was the only way I could get iTerm2 to use the solarized colors in non-GUI MacVim.
  • Can
    Can over 7 years
    As the answer also suggests, Bill Turner's answer is also correct but THIS is the official(hence correct) way to set the solarized theme.
  • Eric Leschinski
    Eric Leschinski over 5 years
    Upvote because this was the clue I needed to try different color presets that lead me to the discovery that color escape codes past 256 are treated differently on mac vs linux. On mac, colors past 256 seemed to be modded than flattened to one of the 8 ANSI colors selected, wheras in linux appears to be doing a modulus which wraps around and picks a color.
  • Dominic Bou-Samra
    Dominic Bou-Samra over 4 years
    This fixed it for me ty