5

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
7

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'
| improve this answer | |
4

An old question but it ranked high on my Google search without helping me. This is what finally solved this for me

In .tmux.conf:

set -g default-terminal "screen-256color"
set -ga terminal-overrides ",*256col*:Tc"

In .vimrc:

if exists('+termguicolors')
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  set termguicolors
endif
| improve this answer | |
  • +1 I searched the whole web, spent hours and hours trying to fix this and it wasn't working until I find this answer. My problem was that after setting the TERM variable on xterm-256color, I had the colors in vim but they weren't the right colors. It was like there is a pink overlay on top of the terminal and everything was getting this pinkish color! For me, the second line of your .tmux.conf file was a game-changer. I simply added set -ga terminal-overrides ",*256col*:Tc" and it magically worked. Thanks a lot! – Saeed Ahadian Apr 23 at 18:07
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.

| improve this answer | |

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.