How to get 256 colors with GNU screen and vim

If you're anything like me -- and let's hope you're not, you've wanted to get vim to look pretty.

There are plenty of color schemes available out there. For a nice repository, I suggest going to the vim color scheme test and finding one you like.

For some reason, even in this modern era, Ubuntu ships screen with 256 colors disabled. And vim in a similar state.

Step 1: Check your terminal

gnome-terminal seems to have 256 colors enabled by default these days. If it doesn't, well, that sucks. here is a small perl script that outputs a grid of 256 colors. It should look like this:

If not, you're doing something wrong. Here is a link to the script, local copy.

Step 2: Vim

Telling vim to use 256 colors is easy. In your .vimrc file, add:

set t_Co=256

That's it. Maybe use a color scheme from above and test, to make sure it looks good.

Step 3: Screen

The wiliest of them all. Ubuntu fixed this by enabling screen with 256 color support around 2008, however, neglected to update the system settings to turn this support on, for whatever reason.

Update your .screenrc file. Add the following:

attrcolor b ".I"
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
defbce "on"

There you go.