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'
     export TERM='xterm-color'

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. Commented Apr 20, 2015 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? Commented Apr 20, 2015 at 11:48
  • I had a similar problem but export TERM=screen-256color just disables all coloring. Commented Dec 14, 2016 at 4:13
  • This worked for me: stackoverflow.com/a/15095377/96855 Commented Dec 14, 2016 at 4:48

3 Answers 3


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
  • 3
    +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! Commented Apr 23, 2020 at 18:07
  • 1
    @SaeedAhadian same! Thanks, @Martin!
    – jrnxf
    Commented Oct 12, 2021 at 18:59
  • Neovim 0.9.1, Tmux 3.3a, Terminator on Kubuntu -- This worked for me Commented Aug 3, 2023 at 15:50

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'

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.

You must log in to answer this question.

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