VIM solarized color scheme looks wrong when using tmux

12,247

Solution 1

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

Solution 2

The issue was the tmux version 1.8. I used advice from here:

https://stackoverflow.com/questions/25940944/ugrade-tmux-from-1-8-to-1-9-on-ubuntu-14-04

Upgraded tmux to version 1.9a, and the problem went away.

Solution 3

I had the same problem with tmux and vim using solarized theme. The problem was solved with the help of this blog post: http://www.terminally-incoherent.com/blog/2012/10/17/vim-solarized-and-tmux/

My steps to solve this problem were:

  1. Upgrade tmux to 2.0 version. (To see what your current version is use: tmux -V)

  2. Add terminal support for 256 color mode (~/.bashrc):

    export TERM="screen-256color"
    alias tmux="tmux -2"
    
  3. Tell tmux what terminal type should be used (~/.tmux.conf):

    set -g default-terminal "screen-256color"
    
  4. Force vim to use 256 colors (~/.vimrc):

    set t_Co=256                        " force vim to use 256 colors
    let g:solarized_termcolors=256      " use solarized 256 fallback
    

Restart terminal for changes to take effect.

Solution 4

Try tmux -2, the -2 means Force tmux to assume the terminal supports 256 colours. I created an alias so that tmux always starts that way.

Share:
12,247

Related videos on Youtube

user1135541
Author by

user1135541

Updated on September 18, 2022

Comments

  • user1135541
    user1135541 almost 2 years

    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

    • user1135541
      user1135541 about 9 years
      I added answer to original question edit. My tmux does have the set-option -g default-terminal "screen-256color" why is it screen?
  • user1135541
    user1135541 about 9 years
    Thank you, this is the problem, changing to screen-256color is a different question that I will ask.
  • user1135541
    user1135541 about 9 years
    Thanks, also I did find a solution, just upgrade TMUX, can be seen here: stackoverflow.com/questions/25940944/…
  • chugadie
    chugadie over 8 years
    this was the only solution that worked on ubuntu 14.04. i tried: upgrading to tmux 2, and adding set-option terminal-256color to ~/.tmux.conf