VIM Color Scheme – Fix Solarized Color Scheme in tmux

gnome-terminaltmuxvim

I am trying to use the solarized color scheme in VIM using gnome terminal (Ubuntu). When I run vim without tmux, it looks great, see below:

enter image description here

If I add the following commands to my .bashrc

# tmux configuration
tmux attach &> /dev/null

if [[ ! $TERM =~ screen ]]; then
    exec tmux
fi

and start the terminal with tmux, the colors do not look right, see below:

enter image description here

Here is the contents of the .tmux.conf file

source ~/.local/lib/python2.7/site-packages/powerline/bindings  /tmux/powerline.conf                    
set-option -g default-terminal "screen-256color"                                                                                                                                          
set-option -g history-limit 10000   

I am using https://github.com/altercation/vim-colors-solarized for the vim color scheme, and the terminal is: https://github.com/Anthony25/gnome-terminal-colors-solarized.

EDIT:
With tmux:

~$ echo $TERM
screen

enter image description here

Without tmux:

~$ echo $TERM
xterm

enter image description here

Best Answer

The value of $TERM must be screen-256color, so that Vim correctly detects the availability of 256 colors. (tmux reuses the terminal definitions of screen, as this tool implements similar multiplexing.)

You either need to set the correct value for TERM inside tmux adding the line

set-option -g default-terminal "screen-256color"

to ~/.tmux.conf, or force 256 colors in your ~/.vimrc via set t_Co=256 (which would be a workaround, and best guarded by if $TERM == 'screen' if you also use non-high color terminals).

Related Question