How do I get the solarized colour scheme working with gnome-terminal, tmux and vim?

42,581

Solution 1

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.

Solution 2

I also found this project:

https://github.com/sigurdga/gnome-terminal-colors-solarized

Thanks for the tips :-)

Share:
42,581

Related videos on Youtube

artfulrobot
Author by

artfulrobot

Stitching together websites, databases and open source cunning to help you change the world.

Updated on September 18, 2022

Comments

  • artfulrobot
    artfulrobot almost 2 years

    There's a lot of questions around this, but it's because there are so many variables. I had to piece together instructions from many sites before I got this working.

    First, I could not easily set up the 16 solarized colour definitions in gnome-terminal (I did it by hand/clicking only to realise that I'd not got the order/mapping correct). Once I fixed that I moved on...

    Then I had solarized colours working in vim OK-ish, but there was some odd black backgrounds appearing in certain highlighting. Once I fixed that, I moved on...

    Then I realised vim went v. wonky once running inside tmux. This is massively debated, but very few of the answers (which mostly say about setting TERM to xterm-256colors) worked for me. I eventually fixed that too.

    Solarized is a very nice palette (although I darkened the darkest base colour and lightened the lightest as I prefer the higher contrast and found tmux's 'white' far far too yellow on my calibrated screen - prob fine on a typical uncalibrated laptop screen as they're usually way too blue!), so I'm posting this question with its answer to share the results of my learning.

  • Koraktor
    Koraktor about 10 years
    set t_Co=16 did the trick for me. Before setting that option syntax hightlighting did not work at all.
  • LondonRob
    LondonRob almost 9 years
    Yes yes and yes! Use this script, don't bother with all the hacking in the accepted answer. This "just works".
  • Admin
    Admin almost 9 years
    It's amusing how much work you need to do to get 16 colours working in a text editor!
  • wchargin
    wchargin over 8 years
    Wonderful! This is so much better. Thank you.
  • JohnMudd
    JohnMudd over 8 years
    On some installs it works. On some it's too blue.
  • artfulrobot
    artfulrobot about 8 years
    Note: I'm finding that in Gnome Terminal 3.18.3 (in Ubuntu 16.04) this no longer works - doesn't seem to accept the colours and using vim's t_Co=256 gives better results.