Background color mismatch in vim and tmux

892

Solution 1

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

Solution 2

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'

Solution 3

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.

Share:
892

Related videos on Youtube

LoserGuy
Author by

LoserGuy

Updated on September 18, 2022

Comments

  • LoserGuy
    LoserGuy over 1 year

    I would like to ask if anyone knows of a good beginner's book/tutorial (or website) for Android. Preferably, presents examples suited for Jelly Bean.

    Thanks a lot.

    • Admin
      Admin about 9 years
      I think you need to set TERM=screen-256color inside tmux.
    • Admin
      Admin about 9 years
      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?
    • Admin
      Admin over 7 years
      I had a similar problem but export TERM=screen-256color just disables all coloring.
    • Admin
      Admin over 7 years
  • Saeed Ahadian
    Saeed Ahadian about 4 years
    +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!
  • coloradocolby
    coloradocolby over 2 years
    @SaeedAhadian same! Thanks, @Martin!