Solarized gives very specific colours. You can't really achieve these colours in a standard 256 colour palette. The only way you can achieve this is through setting up the exact colours in your terminal emulator, then apps think they're just using standard 16 colours (8 + 8 brights) but these have been accurately mapped to the Solarized palette.
Gnome terminal does not provide a very easy way to export/import palettes or profiles, but you can do it with this bash script:
#!/bin/sh
DARK_BG='#000014141A1A'
# original: DARK_BG='#00002B2B3636'
LIGHTEST='#FFFFFBFBF0F0'
# original: LIGHTEST='#FDFDF6F6E3E3'
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/use_theme_background" --type bool false
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/use_theme_colors" --type bool false
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/palette" --type string "#070736364242:#D3D301010202:#858599990000:#B5B589890000:#26268B8BD2D2:#D3D336368282:#2A2AA1A19898:#EEEEE8E8D5D5:$DARK_BG:#CBCB4B4B1616:#58586E6E7575:#65657B7B8383:#838394949696:#6C6C7171C4C4:#9393A1A1A1A1:$LIGHTEST"
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/background_color" --type string "$DARK_BG"
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/foreground_color" --type string "#65657B7B8383"
Nb. here I've overridden Solarized's darkest and lightest colours. You can use the originals if you like, as commented.
Good enough. Now install the Solarized vim colours file by placing that file in ~.vim/colors/solarized.vim
.
Now you can tell Vim to use that colour scheme with colo solarized
. But this did not quite work and I had to tell Vim to use a 16 colour pallete, set t_Co=16
. I stuck both of those in my ~/.vimrc
file.
Now vim colours were working, but not if it ran inside tmux.
This next bit is very confusing. Most advice says about setting TERM
outside tmux to xterm-256colors
, but when I did that tmux would not even start. It confused me, too: doesn't solarized say that the 256 colour palette is a poor approximation? Well, it is confusing, and anyway, it wasn't working so I needed another way forward:
Create a file /tmp/foo
containing:
xterm-16color|xterm with 16 colors,
colors#16, use=xterm,
Then install this with sudo tic /tmp/foo
Finally, alias tmux
as follows:
alias tmux='TERMINFO=/usr/share/terminfo/x/xterm-16color TERM=xterm-16color tmux -2'
I now get exactly the right colours in the terminal, in vim, and in vim-inside-tmux. Nb. the -2
option tells tmux
to use a 256 colour palette, which is really confusing because the env variables would appear to be telling it otherwise... I genuinely don't know, and I'm afraid I don't really care to climb that learning curve because I now have a beautiful coloured terminal that Just Works.
There is some information on 256-color support in the tmux FAQ.
Detecting the number of colors that the terminal supports is unfortunately not straightforward, for historical reasons. See Checking how many colors my terminal emulator supports for an explanation. This means that
- tmux cannot reliably determine whether the terminal supports more than 8 colors;
- tmux cannot reliably communicate to the application that it supports more than 8 colors.
When you're in tmux, the terminal you're interacting with is tmux. It doesn't support all of xterm's control sequences. In particular, it doesn't support the OSC 4 ; …
control sequence to query or set color values. You need to use that while directly running in xterm, outside tmux.
If you run tmux -2
, then tmux starts with 256-color support, even if it doesn't think that your terminal supports 256 colors (which is pretty common).
By default, tmux advertises itself as screen
without 256-color support. You can change the value of TERM
in .tmux.conf
to indicate 256-color support:
set -g default-terminal "screen-256color"
You can use TERM=xterm-256color
or TERM=screen-256color
on Ubuntu. These values will only cause trouble if you log in to a remote machine that doesn't have a termcap/terminfo entry for these names. You can copy the entries to your home directory on the remote machine; this works with most modern terminfo implementations.
# From the Ubuntu machine to a machine that doesn't have *-256color terminfo entries
ssh somewhere.example.com mkdir -p .terminfo/s .terminfo/x
scp -p /lib/terminfo/s/screen-256color somewhere.example.com:.terminfo/s/
scp -p /lib/terminfo/x/xterm-256color somewhere.example.com:.terminfo/x/
Best Answer
Short answer
It's a bug.
Full answer
It looks like the "correct" visualisation is the one on the left, where the bold font are not rendered. For what I could understand (here is the reference) the bold attribute was used, originally, to set the highlighted version of the 8 base colours.
Basically, what is happening here is that, in order to use the full Solarized palette, with the orange, purple and all the levels of grey, the colours are called with the bold attribute, which in turn refers to the alternative 8 colours of the ANSI palette.
Terminal understands this correctly, and shows the orange and the comment grey in normal typesetting, whereas tmux adds an unnecessary bold font to them. In conclusion, the left side is correct whereas the right one is not.
Question 2
Is there a way to disable the bold rendering of tmux?
I still have to do some research about it, and I will update this answer as soon as I find something.
Answer 2
And here we have the solution! :)
In order to have tmux behave correctly we have to call it telling him that we are in a 256 colours enabled environment.
For convenience we could
alias
this (i.e. you addalias tmux="<the line above>"
to your~/.bashrc
).Calling
tmux
astmux -2
, for forcing tmux to run with 256 colours support (instead of redefining theTERM
environmental variable) will not allow for correct interpretation of the "bold-alternative" 8 colours (i.e. the brighter variant will also result having a bold typesetting). Therefore, I highly recommend to use the solution here above for having both correct 256 colours interpretation and non-bold "bold-alternative" colours.