Colours on Vim and tmux
When using Vim (7.3) through tmux (1.8) I found that the Vim colour scheme looked strange. After much googling this was the solution that worked for me.
Set the following in your
Set the following in your
set -g default-terminal "screen-256color"
This was very much trial and error3 but seems to work across both OS X and Debian boxes.
EDIT (5/12/13): Since I was struggling to understand colours in the terminal, I emailed the knowledgable @geraintrjones who sent me an excellent explanation (with some brilliant Serengeti animal analogies):
Terminal emulators tell the world about their capabilities with something called a
$TERMvariable is a label that says “I am this kind of thing” - for instance, OS X’s Terminal.app has its default
xterm256-color. You can see this by typing
echo $TERMin the terminal. (you might see something else, and this is where the problem starts…)
This doesn’t tell you much on its own, but there is a big database called
terminfothat lists all the
$TERMvariables, and what features something with, say,
Its like a label saying ‘Elephant’. When you look up ‘Elephant’ in the animal list, you see it has 4 legs, a trunk, and can support palanquins but requires a mahout.
You can see the
terminfoentry for your terminal by typing
infocmp $TERM(which will look up that terminal’s
$TERMin your system’s
You will see the number of colours listed like this:
xterm256-colorfor instance, will show
This means that OS X’s Terminal.app is telling the world it can handle that number of colours. Applications like Vim see a label saying “I have all the xterm-color features!” and think, “Okay, I’d better give this old timer 8 colours”. Or they see
xterm256-colorand think, “Lets give this dude 256 colors”.
What should happen, is that tmux reads the
$TERMvalue of your terminal, sees
xterm256-color(or similar) , thinks “Okay, that’s a 256 colour terminal” and sets its
screen256-color. Vim running in tmux then reads tmux’s
$TERMand goes, “Cool, I looked
screen256-colorup and it has 256 colours - let me crack out the 256 colour palettes, like a colourful boss”.
Terminal tells tmux its an Elephant, tmux tells Vim its an Elephant, Vim gets the mahouts out and preps the palanquin.
Whats probably happening is that your
.bash_profileis setting a different
$TERM- for instance,
Tmux then goes, “Okay, this is an 8 colour terminal, I’m gonna set my
screen”, which only has 8 colours. Vim then reads tmux’s
$TERMand serves up a paltry 8 colours only.
So, terminal is telling tmux its an Antelope, so tmux tells vim its an Antelope, Vim leaves the mahout at home and you don’t get a palanquin, even though you could handle that sh_t.
So by setting
set -g default-terminal "screen-256color"in your
.tmux.conf, you are telling tmux to always set its
screen-256color, and then apps like Vim will look that up in
terminfoand see, yup, supports 256 colours.
.bash_profilegets run every new terminal right - so it’s run again , overriding the
So, telling vim to use a different
set term=screen-256colorin your
.vimrcmakes it use the features
screen-256color,which includes 256 colours. You can use
infocmp screen-256colorif you’d like to see this.
So Tmux says, its an Elephant, then your
.bash_profilechanges the label to Antelope - then you have to have Vim tell itself “ignore that, its really an Elephant”.
Only setting the Vim
$TERMmeans tmux isn’t set up for 256 colour, so Vim tries giving 256 and fails. Only setting the tmux one means tmux is loaded for 256, but due to the
$TERM, everything thinks tmux is only prepped for 8.
Really, you shouldn’t be trying to override
.vimrc- because now, whenever you open Vim it thinks it’s in a terminal that has all the
screen-256colorfeatures. This is only the case when its being opened in tmux!
Really really, you shouldn’t be overriding tmux either - if you make sure your terminal (in this example, OS X’s Terminal.app) has its
$TERMset correctly, tmux will read it, see it can handle 256 colors and automatically set its
The best solution would be to gently reassure the terminal that it is in fact an Elephant after all. Which probably means nixing a rouge
export TERM=xterm-colorfrom your
echo $TERMin a new terminal. If it doesn’t say
xterm256-color, go look at your
.bash_profileand wipe out any evil