lose vim colorscheme in tmux mode
Solution 1
I had the same problem. Only difference was I am using solarize
rather then molokai
.
To fix the issue, I have set up an alias in ~/.bashrc
:
alias tmux="TERM=screen-256color-bce tmux"
And set up the default-terminal
option in ~/.tmux.conf
:
set -g default-terminal "xterm"
Lastly, do $ source ~/.bashrc
to load new alias.
Solution 2
I tried all the solutions above and what finally worked for me is putting the following lines in .tmux.conf
:
set -g default-terminal "xterm-256color"
Solution 3
As @romainl mentions above, I needed to force tmux to use 256 colors by adding the -2
flag:
$ tmux -2
I added alias tmux='tmux -2'
to my bash_profile, so, I don't forget :)
Solution 4
I just discovered why I was having a lot of confusion. I, like others here, was having a difficult time getting the default-terminal setting to take effect. I remembered that I had a tmux session in the background. I re-attached my session, closed out my processes, and closed ALL tmux processes. The next time I restarted tmux the default-terminal setting in .tmux.conf
began to take effect. I don't know if others are doing this as well but I recommend closing all tmux processes before modifying the .tmux.conf
file.
I got my setup to work on my local machine (OSX 10.9.5 with iTerm2) without any modification to .bashrc
or .bash_profile
. All I did was add the line set -g default-terminal "xterm-256color"
to ~/.tmux.conf
and restarted all tmux processes.
I got my remote setup (ssh to Ubuntu 14.04) to work exactly the same way without any modifications to .bashrc
. I simply added set -g default-terminal "xterm-256color"
to ~/.tmux.conf
on my remote machine and restarted all remote tmux processes.
You can test what Vim is seeing by doing echo $TERM
from within a tmux session. It kept saying screen
as the value until I restarted all tmux processes, at which point it reflected xterm-256color
as expected.
Hope that helps.
Solution 5
So this a bit on the stale side, but it's might be worth mentioning that using screen will often break the Home and End keys. Using
export TERM="xterm-256color"
in should keep the functionality of these and allow the color scheme (or powerline) to work fine.
Related videos on Youtube
tristen
A developer and designer residing between Washington, DC and Toronto, Ontario
Updated on September 28, 2021Comments
-
tristen over 2 years
I'm running iterm2 and when I'm in tmux mode the colorscheme I have set in vim does not show up. Only the color scheme I've set in iterm. If I run vim from shell the colorscheme appears correct - its only when I'm in tmux mode.
I've tried setting
:colorscheme molokai
when in vim (see screenshot below) and it doesn't change - again, the default colorscheme for iterm2 remains.Am I missing some setting to iterm or tmux.conf? My dotfles are up on github here.
-
romainl about 12 yearsWhat happens when you do
$ tmux -2
? -
tristen about 12 yearsThat was totally it. What's the -2 flag?
-
romainl about 12 yearsIt forces tmux to work with 256 colors.
-
rodorgas over 3 years@romainl something good happens :)
-
-
romainl about 12 yearsActually, it's not mandatory at all: I don't use
-2
but I have 256 colors working in Vim in tmux. -
thameera about 11 yearsI use this instead of
tmux -2
as this is more verbose. -
waffl almost 11 yearsPersonally I had to use
set -g default-terminal "screen-256color"
to work rather thanxterm
on OS X, sshed into an Ubuntu box. I referred to this site: rhnh.net/2011/08/20/vim-and-tmux-on-osx -
Jpatrick over 10 yearsThanks for pointing this out. I didn't know that. It still seems to work for Debian derv from what I've seen so far. In my defence the post was in reference to OSX.
-
Gilles 'SO- stop being evil' about 10 yearsThe alias here doesn't make sense: it's pretending to tmux that it's running inside screen or tmux, which is hardly ever the case. To tell tmux to assume that the terminal it's running in supports 256 colors, run
tmux -2
ortmux -2 attach
(tmux decides each time you attach a new or existing session to a terminal). A sensible alias would bealias tmux='tmux -2'
. See also tmux, TERM and 256 colours support -
Gilles 'SO- stop being evil' about 10 years@romainl It's necessary if tmux doesn't detect your terminal as having 256 colors, which is fairly common.
-
romainl about 10 years@Gilles, Vim doesn't detect that the terminal supports 256 colors because tmux's default
TERM
isscreen
.-2
doesn't changeTERM
and doesn't change anything color-related to what info Vim gets from its environment::echo &t_Co
still returns8
. With the info it is given, Vim does the right thing. The only things that must be set are 1. your terminal emulator'sTERM
toxterm-256color
or an equivalent value likeurxvt-unicode-256color
and 2. tmux's defaultTERM
withset -g default-terminal "screen-256color"
. -
Gilles 'SO- stop being evil' about 10 years@romainl Most environments have
TERM
set toxterm
, notxterm-256color
, hence the need to runtmux -2
(orTERM=xterm-256color tmux
, or change the termcap or other ways of accomplishing the same thing). -
romainl about 10 years@Gilles, the problem is that -2 doesn't accomplish anything that has any impact on Vim's behavior regarding 256 color support because the only thing that matters to Vim is your TERM and that's to be set at your end of the chain: in your terminal emulator. If you SSH through 5 hosts and your terminal is set correctly, Vim launched on the 5th host will see your 256 colors TERM and act accordingly. If you use tmux at any point of the chain -2 will have zero impact on Vim's behavior because all it sees is its environment is limited to 8 colors because of tmux's default TERM: screen, -2 or not.
-
Gilles 'SO- stop being evil' about 10 years@romainl You need to take care of both the outside (
-2
orTERM=xterm-256color
or setting thexterm
termcap/terminfo to declare 256 colors) and the inside (set -g default-terminal "screen-256color"
or setting thescreen
termcap/terminfo to declare 256 colors). -
romainl about 10 years@Gilles, which is almost exactly my point except that -2 is pointless since it's so easy to
-
agenteo about 10 yearstmux 1.9a, OSX 10.9.2, iTerm2 Build 1.0.0.20130622 export TERM="xterm-256color" in .bash_profile, then set iterm to xterm-256-color worked for me. No need to set any tmux configuration.
-
armen.shimoon almost 10 yearsI am using tmux via SSH and this is also what worked for me even though I am not using xterm, just regular SSH.
-
Chev over 9 yearsI wasn't using it over ssh and this was the only answer that worked for me. Local iTerm session in OSX 10.9.5.
-
marcelocra over 9 yearsI read in some other answer (couldn't find the reference) that it was not a good practice to force the TERM, though I don't know for sure. Since the
tmux -2
option with theset -g default-terminal "screen-256color"
worked for me, that will be my choice. But thanks anyway! -
Chev over 9 yearsI've confirmed on several more operating systems since this post, closing all processes and setting the
default-terminal
option in.tmux.conf
has worked 100% of the time so far. -
Chev over 9 yearsIf the
.tmux.conf
setting doesn't appear to be taking effect, close all tmux processes and restart. You can just doset -g default-terminal "screen-256color"
without setting any alias in.bashrc
. I think people are doing workarounds like the environment variable alias because they aren't closing all tmux processes after configuring.tmux.conf
. -
erran over 9 yearsI ended up exporting
TERM
asxterm-256color
and addingset -g default-terminal "xterm-256color"
to my tmux config. In my OS X terminal profile I ensured that the terminal was declared asxterm-256color
as well. I ensured that my terminal profile was set to the same TERM type. This works preserves my fish shell and vim themes. -
PhilT over 8 yearsTo confirm, just adding
set -g default-terminal "screen-256color"
to.tmux.conf
worked for me. Thanks. -
trigoman about 8 yearsI had the issue with mintty, and adding the vim configuration fixed it for me. I didn't even need to do the
tmux
alias. -
Masood Alam almost 8 years@trigoman , same for me too, i just had to update the .vimrc.
-
vesperto about 7 yearsThe
default-terminal
here didn't help me, vim kept starting up with weird bindings (i.e. Home/End keys switching to insert mode and inserting F and H plus newline). I set an alias in my .bashrc instead:alias vim='TERM=xterm vim'
-
Mike over 6 yearsI tried all of the previous suggestions. Just added
set t_Co=256
to .vimrc and it was fixed. I didn't need to create atmux
alias. -
Adam Erickson over 6 yearsSame here. Thank you @waffl for finding this solution!
-
Sigfried about 6 yearsme too! i would have spent less time on this if this answer were farther up.
-
Blaszard almost 6 yearsThis worked perfectly on vim but for some reasons started to be messed up on neovim, especially since all the comment-outs now have background highlight...
-
volk over 5 yearsonly thing that worked for me. what exactly does this do?
-
llinfeng over 5 yearsHave tested these two lines, and they work well for my Vim on WSL-Windows10.
-
Foobar over 5 yearsThanks a lot. This worked on Ubuntu 18 with gnome-terminal
-
Richard Domingo about 5 years@seyeong-jeong Can you kindly edit the answer to include this answer? Would've saved me some time if I saw this earlier. Thanks!
-
Adrian Magdas about 5 yearsThis works for me (MacOS Mojave + iTerm2/Alacritty), thanks
-
markovchain over 4 yearsThis is what worked for me. Just plain export of TERM. +1
-
Saeed Ahadian about 4 yearsI'm using CentOS 8 and for me, the right configuration was
set -g default-terminal "xterm-256color"
in my~/.tmux.conf
. I also didn't need to make any changes to my.bashrc
file for it to work. -
sammy almost 4 yearsWorks on Ubuntu 20.04
-
fracca almost 4 yearsIndeed, this is the correct solution, particularly on Ubuntu 20.04
-
lajarre over 3 years⚠️ See @Chev 's answer below: stackoverflow.com/a/25940093/931156
-
Ambareesh over 3 yearsWorked like a charm!
-
ruohola over 3 yearsThis worked for me, using iTerm2 on macOS Catalina.
-
JohnnyD27 about 3 yearsThis was the only thing that worked for me on RedHat using xterm. Thanks!
-
markson edwardson almost 3 yearsIt enables true color support. The current recommendations have changed for 3.2 (
set -as terminal-features ",xterm-256:RGB"
) github.com/tmux/tmux/wiki/FAQ#how-do-i-use-rgb-colour -
LeOn - Han Li about 2 yearsThis works great for
tmux/neovim/alacritty
. Thanks a lot! -
G-J about 2 yearsSomething recently broke my vim color scheme on a WSL2 installation of Ubuntu on WIndows 11, running inside Windows Terminal. This was the correct fix.
-
dc_Bita98 almost 2 yearsworked for me on Ubuntu 22.04 with gnome