70

I installed Ubuntu 11.10. Then downloaded Solarized theme for Gnome Terminal. From terminal my vim looks good: plugin vim-powerline displays correctly and syntax is highlighted with proper colors. But when I run tmux and there run vim - syntax highlight uses only one basic color and vim-powerline displays no colors. I looked at the FAQ on vim-powerline and solution should be this line in .tmux-config:

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

But it doesn't work. I looked at TERM and it's return 'xterm' so I tried:

set -g default-terminal "xterm-256color"

But this also dosen't help.

This is the only line in .tmux.config. In .vimrc I have following lines:

call pathogen#infect()
set nocompatible
set encoding=utf-8
set laststatus=2
let g:Powerline_symbols = 'fancy'
set t_Co=256
syntax enable
set background=dark
colorsheme solarized
1
  • No idea why you got no upvotes, not even from those who must have benefited by getting upvotes from their own answers. +1 from me. The question is sound and it helped me solve my own problem, too, by finding it. Jan 21, 2013 at 16:09

13 Answers 13

63

Starting tmux with the following flag fixes this for me:

tmux -2

from tmux man page:

-2 Force tmux to assume the terminal supports 256 colours.

2
  • 1
    Good hint. When the Cygwin version of screen started to crash vim I switched back to tmux again very quickly. Love it.
    – grantbow
    Jun 20, 2015 at 3:56
  • 1
    FYI - This was the only thing that worked for me with tmux 2.3 and the latest powerline. Colors in vim and tmux status bar were really weird. Apr 24, 2017 at 5:20
38

this worked for me

in .tmux.conf

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

in .vimrc

set term=screen-256color

remove old term value for .vimrc, believe me this will work

3
  • 2
    Doesn't work for me. tmux 1.8, vim 7.4.1816, ubuntu x86_64 with kernel 3.13.0-92-generic. FYI.
    – fstang
    Sep 12, 2016 at 3:10
  • 3
    It worked for me without .vimrc settings, only .tmux.conf. Dec 24, 2016 at 20:31
  • 2
    The .tmux.conf setting did the trick for me!
    – hesselbom
    Nov 7, 2018 at 13:43
33

I am having the same problem on Ubuntu 10.04 LTS using Byobu 5.17 & tmux 1.5 using the latest Solarized from the GitHub repo.

I was able to partially fix this by specifying $TERM in the .bashrc file:

export TERM="xterm-256color"

It seems, also, that there is a bug filed on launchpad, but it is not yet resolved: byobu not displaying dircolors properly

3
  • 2
    This is the only thing that worked for me!
    – Tranquille
    Jan 28, 2016 at 23:37
  • Also worked on Ubuntu 14.04 with tmux 2.0
    – davetapley
    Mar 16, 2016 at 23:14
  • This is the solution on OS X as well haha
    – Jay
    Jun 21, 2016 at 23:49
8

To me it looks like nobody knows what is talking about...


How does our opening procedure works:

  1. open a terminal (whichever)
  2. open a tmux
  3. open vim/nvim

1 Terminal

Open a terminal (whichever you use - I use st) and write a command:

┌───┐
│ $ │ ziga > ziga--workstation > ~
└─┬─┘
  └─> echo $TERM

st-256color

As answer I got a string st-256color because this string is compiled as the C string literal termname in the st (check here). It is similar with whichever terminal you use. Somewhere in the binary there is a string literal that is set as a enviromental variable TERM when terminal is started.

Here you can't do anything but to remember this string.


2 Tmux

Now lets continue the chain... tmux is opened after your terminal. In configuration file ~/.tmux.conf I must now first make sure to identify enviromental variable TERM that my terminal set. So I write like this:

set-option -sa terminal-overrides ",st*:Tc"

This line checks if enviromental variable $TERM starts with st (therefore st*) and makes sure to use true color (Tc) because current "indexed colors" (8 bits = 2^8 = 256 colors) is not enough for us. We want tmux to use "true colors" (24 bits = 2^24 = 16777215 colors). Here we could add some more lines just to be sure we will match the value of TERM. In my case the below line also works because it searches for 256col in the middle of TERM:

set-option -sa terminal-overrides ",*256col*:Tc"

And if I would use xfce4-terminal that sets TERM = xterm-256color I could use a line like this instead:

set-option -sa terminal-overrides ",xterm*:Tc"

So far tmux is covered. But before we continue the chain, we must make sure that tmux as well will export it's enviromental variable TERM.

In this case we can set it to whatever we want using this line inside the ~/.tmux.config:

set -g default-terminal "tmux-256color"

Now make sure to exit the tmux and kill it's server:

tmux kill-server

Then enter tmux by using command tmux and execute command:

┌───┐
│ $ │ ziga > ziga--workstation > ~
└─┬─┘
  └─> echo $TERM

tmux-256color

You should get answer tmux-256color. Now we can continue to vim...


3 Vim

In our final step we just have to configure vim by adding this line inside it's configuration file ~/.vimrc:

if exists('+termguicolors') && ($TERM == "st-256color" || $TERM == "tmux-256color")
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
    set termguicolors
endif

This properly sets escape sequences &t_8f and &t_8b and finally sets "true colors" inside vim. But this is done only if TERM value is:

  • st-256color (when I open vim directly in the st terminal without opening tmux prior to that)

  • tmux-256color (when I open vim while already in tmux)

If you are using multiple terminals, here you should add them like this:

if exists('+termguicolors') && ($TERM == "st-256color" || $TERM == "tmux-256color" || $TERM == "xterm-256color")
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
    set termguicolors
endif

Otherwise colors will not work across all the terminals... Good luck!

6

Terminal type should be set to screen-256color in ~/.tmux.conf. It tells tmux what to set the TERM evironment variable, so it won't work for the current session - start a new one and test then.

If it still doesn't work, you can run Vim using:

TERM=screen-256color vi

This sets the environment variable just for a one-off vi execution.

If that doesn't make vim display all the colours, test if your terminal (I'm not sure if you're testing with just one terminal emulator) is compiled to support the 256 colour palette - download and run the below Perl script from the terminal emulator in question.

http://scie.nti.st/dist/256colors2.pl

PS. I assume you've already corrected the typo jordanbrock noticed.

2

As explained by Marcin Kaminski, if TERM=screen-256color vim <filename> works for you then just add following to your .bashrc

TERM=screen-256color

and following in your .tmux.conf:

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

I had the same problemd, this works for me.

2
  • This was the only one that worked for me (tmux 1.8).
    – Yamaneko
    Sep 13, 2016 at 23:04
  • Actually, I just tested, and only changing TERM=screen-256color was enough for me, independently of setting tmux to screen-256color or to xterm-256color. Thank you!
    – Yamaneko
    Sep 13, 2016 at 23:18
1

There's a typo in the last line of your .vimrc.

It should be colorscheme solarized

Not sure if that helps :)

0

You may be having the same problem documented in this answer.

Basically, .tmux.conf setting works, and TERM is set to screen-256color, but then tmux opens bash and calls your .bashrc, which sets TERM to something else (perhaps xterm-256color).

The solution is to set TERM in your terminal settings rather than in .bashrc. If that's not an option, you can check TERMinside .bashrc and not change it if it's already screen-256color.

0

In the shell starting tmux, check that $TERM is either xterm-256color or screen-256color. See how to change $TERM:

As an alternative, as Holy Mackerel said, you can force tmux to 256color via:

$ tmux -2
0

[Solucion][1] that may disturb your vision and make Vim unpleasant to use for an extended period of time.

You can fix this by running :set term=screen-256color in Vim or by relaunching Vim under the TERM=screen-256color environment, as some experts recommend: http://sunaku.github.io/vim-256color-bce.html

1
  • 3
    What do you mean by [Solucion][1]? Were you trying to refer or link to another answer? Answers don't always appear in the same order. I recommend expanding this to clarify what you're saying may "disturb your vision and make Vim unpleasant to use for an extended period of time." Aug 11, 2014 at 15:32
0

In your .bashrc or .zshrc just add

if [[ $TERM == xterm ]]; then
    TERM=xterm-256color
fi

and also start with the tmux -2

0

For those, who is consuming time on colors, and if solarized vim doesn’t work on tmux, or tired of finding colors of vim, this should work in a minute, also it is from the official repository as follow.

yum install vim-jellybeans

or

mkdir -p ~/.vim/colors
cd ~/.vim/colors
curl -O https://raw.githubusercontent.com/nanotech/jellybeans.vim/master/colors/jellybeans.vim
touch ~/.vimrc 
sed -i '/colorscheme/d' ~/.vimrc
echo colorscheme jellybeans >> ~/.vimrc

this will fix it with the beautiful color set and patterns are so focused and useful, if you are also tried to set those highlight, search words, this is it. everything has already set to use. You can even change colors in the configuration file.

If you don't want to install anything but just simple quick solution, ignore above and try this in vim

:colo ron you can also replace 'ron' with the following sets and even restore to solo default

blue 
darkblue 
default
delek
desert
elflord
evening
koehler
morning.vim
murphy
pablo
peachpuff
ron
shine
slate
torte
zellner

and save in .vimrc

colo ron
syntax on
0
0

Before:

Before

After:

After

For me the problem was caused by these lines I had from macos based .vimrc.

set t_ZH=^[[3m
set t_ZR=^[[23m
set termguicolors

As soon as I commented out these 3 vim colors got back to normal in Ubuntu.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .