I have spent the last couple of days trying to understand why I couldn’t get Vim to display the correct 16 colours in the console. Not in a terminal emulator in X, like xterm or rxvt-unicode, but in the consoles, TTY1-6.
After a lot of searching, more reading into the
arcane documentation
of Linux terminals than I was either prepared for or keen on and some
experimentation, I have it working. With one caveat; I wasn’t prepared
to set the TERM
environment in my .vimrc. Apart from being
cautioned against,
as I do set it for tmux, I was anxious to avoid any clashes when
running Vim in tmux
(which I do most of the time).
From the top, then. Logging into a console and checking the $TERM
and
colours, gave me the default:
1 2 3 |
|
Which, under my current configuration of Vim, rendered colours like so:
Hardly satisfactory.
The first step was to remove the line in my .vimrc that was forcing 256 colours:
1
|
|
Then I had to rewrite my colourscheme to change all of the references to the terminal colour numbers to colour names, as apparently that is what 8-colour terms accept. So, my miromiro.vim, went from looking like:
1 2 3 4 |
|
…to the more literal:
1 2 3 4 |
|
Once I had made the necessary changes, I saved this new colourscheme as
miro8.vim1. And, yes, I know I could
have included it in an if
condition in my original colourscheme2,
but I was intent on keeping things compartmentalized until I had it working…
Running Vim in the console was now starting to look promising:
The final piece of the puzzle was to pass my X colours to the console. Fortunately, Aaron Griffin’s 2006 post made this a trivial exercise. With the following lines in my .bashrc:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Then it was just a case of setting the relevant colourscheme in my .vimrc:
1 2 3 4 5 |
|
And you can see a screenshot of the finished product on Flickr.