Vim Solarized on OS X Terminal.app Incorrect Colors

marcaddeo picture marcaddeo · Dec 30, 2012 · Viewed 9.7k times · Source

Possible Duplicate:
Why don’t most vim color schemes look as nice as the screenshot when I use them?

I'm trying to transfer my vim configuration to be using it only from the terminal. Currently i'm using gVim and everything works fine.

But in terminal.app, the color scheme is off.. I'm using the Solarized 256 theme for terminal.app and the solarized theme in vim.

This is what they look like:

gVim left, Terminal.app Right

I had to set g:solarized_termtrans = 1 to get ti background to even show the right color.

Answer

greduan picture greduan · Dec 30, 2012

I had this problem myself once.

However the following statement fixed everything, here's how I control Terminal support in my .vimrc file: https://github.com/Greduan/dotfiles/blob/8b48b0d788c0fed6fc14720bbe3ae9def31af947/vim/vimrc.vim#L550-L556

if !has('gui_running')
    " Compatibility for Terminal
    let g:solarized_termtrans=1

    " Make Solarized use 16 colors for Terminal support
    let g:solarized_termcolors=16
endif

Which basically fixes it for Terminal if you're using Terminal. Try using :let g:solarized_termcolors = 16.

Pseudo code:

  • If the user isn't using a GUI:
    • Then set the termtrans equal to one.
    • And tell Vim to only use 16 colors, or 256 if your Terminal supports it (don't know one that does).
  • Endif

EDIT 1:

If you are sure you're using a 256 color terminal then you can also just leave this alone and it'll work perfectly. Like so: https://github.com/Greduan/dotfiles/blob/6dac113d8281b0201399831bf62a2ea520d28154/vim/vimrc.vim#L551-L561

if !has('gui_running')
    " Compatibility for Terminal
    let g:solarized_termtrans=1

    if (&t_Co >= 256 || $TERM == 'xterm-256color')
        " Do nothing, it handles itself.
    else
        " Make Solarized use 16 colors for Terminal support
        let g:solarized_termcolors=16
    endif
endif

What this does is check if you have a Terminal. If it does set termtrans, then check if your Terminal has 256 colors, if it does leave it alone, if it doesn't then set Solarized to use 16 colors. This works out much better.