4

I'm having trouble getting the full range of colors to work in vim when I'm running through tmux. I belive that it's some sort of trouble with TERM variables or 256colors, but I've done everything I have been able to find online to get 256 colors working in vim, tmux, and iTerm, and nothing has fixed it. It's a small problem, but it seriously bugs me.

Here's an example code file in vim just through iTerm: iTerm

and here's the same file in vim through tmux and iTerm: enter image description here

Notice how the background colors seem slightly mismatched, only when code is written there. Why could this be?

I have set t_Co=256 in my vimrc, my iTerm terminal is set to xterm-256color, I have set -g default-terminal xterm-256color in my tmux.conf, and I have:

if [ -e /usr/share/terminfo/x/xterm-256color ]; then
     export TERM='xterm-256color'
else
     export TERM='xterm-color'
fi

in my .profile. This exact issue is replicated on my Ubuntu based machine at work, and I use all of the same configuration files there. This at least isolates the issue as not being OS/iTerm related.

  • I think you need to set TERM=screen-256color inside tmux. – Ingo Karkat Apr 20 '15 at 11:44
  • I've tried it, it doesn't work. Out of curiosity, why would that be better than xterm-256color? Actually, I take that back. I tried setting it in my tmux.conf which didn't fix anything, but if I run export TERM=screen-256color from inside tmux it fixes it. Why does that make sense? – The Wind-Up Bird Apr 20 '15 at 11:48
  • I had a similar problem but export TERM=screen-256color just disables all coloring. – Olivier Lalonde Dec 14 '16 at 4:13
  • This worked for me: stackoverflow.com/a/15095377/96855 – Olivier Lalonde Dec 14 '16 at 4:48
5

After adding the line below into .tmux.conf

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

You still need to add the line below into .vimrc

set term=screen-256color

Finally, the alias need to be added to .bashrc

alias tmux='tmux -2'
2

Inside tmux, you need to set TERM=screen-256color. It may be something like here that this only works from inside tmux, but not in tmux.conf. Check that you don't unconditionally overwrite the TERM value, e.g. in your .bashrc, or anything that gets sourced when you open a shell inside tmux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.