As a rule, I tend to use the dark Solarized theme for my terminals, and the light one for my Vim. Why? I don’t know. I prefer to edit text with dark text on a light background, but dark on light terminals look weird to me. Plus, the stark contrast between backgrounds makes it easy to distinguish an editor pane from a shell pane in Tmux.
Sadly, depending on your system, half the time you open Vim inside of Tmux, Solarized theme (both light and dark) look like shit. This only happens when running the console version of vim from inside Tmux. I hardly ever have issues with the Solarized theme in the command line vim when running it directly. But when it is launched from inside of Tmux, the color scheme is off and moving the cursor introduces strange artifacts on the screen.
Why does that happen? I’m not entirely sure. It appears that Tmux happens to be very finicky about terminal types, and tends to default to 16 color mode rather than the 256 color one required to use Solarized themes. Fortunately, you can usually force it to behave properly by following these steps:
First, set your terminal (Konsole, iTerm2, Putty) to identify as:
Why screen? Because Tmux is a screen-like program, but it likes to inherit the terminal type from the terminal that launched it. You could also use xterm-256color but in my testing setting it to screen worked every time, while xterm setting was problematic under some combinations of terminals and shells.
Next, add these two lines to your .bashrc:
export TERM="screen-256color" alias tmux="tmux -2"
Again, we are once again telling Tmux the terminal type is screen-256color regardless of what the Terminal says. The $TERM environmental variable is the second place where Tmux likes to inherit it’s terminal type from, and if you have a miss-match between the value declared by your actual terminal, and by your shell then Tmux gets confused. The second line forces Tmux to always start in 256 color support mode.
In your .tmux.conf add this line:
set -g default-terminal "screen-256color"
As you can see we are covering all the bases. The point is to give Tmux no choice but to use screen-256color terminal type, regardless of what it might want to do.
Finally, in your .vimrc add these two lines:
set t_Co=256 " force vim to use 256 colors let g:solarized_termcolors=256 " use solarized 256 fallback
Once you do all of this, the Solarized theme should work from within Tmux. I have tested this setup on Kubuntu with Kterm as well as on Windows with Putty and it worked in both. If you know of a better way of ensuring that Vim + Solarized work with Tmux, please let me know in the comments.