I couldn't get my colour schemes looking nice in Vim under tmux and it took me a while to sort it out. Here's what I did. Using:
The steps are:
- Get tmux running in 256 colours
- Add some stuff to your Vim start-up
- Select an appropriate colour scheme
I'm kind of a newb at messing with this type of thing so would be keen to hear about any errs, omissions or inefficiencies :) This is mainly a record for me and maybe helpful to anyone else with similar noob levels of experience trying to sort out a similar problem.
Get Tmux Running in 256 Colours
First of all I needed to get tmux working in 256 colour mode as is it was only running in 16 colours and was the cause of every Vim colour scheme I tried look very horrid. How did I know the amount of colours tmux was using? There's handy Perl script called 256color.pl which you can get here. Running it gave me this:
When I should be getting this:
There's a number of solutions on the web that involve changing the term type in your .tmux.conf file. I had varying success with these and found the easiest thing to do wasn't fiddling with the tmux configuration file but launching tmux with the TERM environment variable to something 256 colour-ish:
And then I got the right output from 256color.pl. Phew!
I didn't want to type TERM=xterm-256color tmux every time I wanted tmux so I added this to my .zshrc file (.bashrc if you're running bash I guess)
alias tmux="TERM=xterm-256color tmux"
Add Some Stuff To Your Vim Start-up
Vim needs to know there are 256 colours for it play with so you need to tell it in your .vimrc. That's pretty easy, just add this line:
Select An Appropriate Colour Scheme
I have a shit load of Vim colour schemes installed from some bundle I got from here :D What I didn't realise is not all of them will work properly in Vim as they were designed for Gvim. To find ones that did I type:
And I get a list of all the schemes designed for 256 colours. A bunch of schemes without 256 colours in the name work as well but it's a bit hit and miss whether they do.
And here we are using wombat256 :)
Why Do This? Why Not Stick With Gvim?
Gvim was getting a little bit slow for me from time to time so I was hoping that using the terminal would be a bit nippier. Is it? Yeah a little I guess. What turned out to be a bigger advantage was being able to keep together a bunch of shell processes together as a session I could attach and detach from. I'm currently doing some hobby coding with ClojureScript and to develop for that I need to be running:
- cljs compiler auto-building any files that change
- http server
- Irc (obviously)
They're all terminal apps (I use irssi) and this makes it easy to have all of them running nicely together in split windows as per below. There's no http server on that screen. It's running as part of the tmux session but as I don't need to see it's output very often I just run it in another window.