Using colour schemes with vim and putty

I am trying to use the desert color scheme with VIM 7.0 on CentOS 5.6 x64 located here:

http://hans.fugal.net/vim/colors/desert.vim

I've downloaded the file and saved it in my ~/.vim/colors directory. I then tell VIM to use the colour scheme by issuing:

:colors desert

It's supposed to look like this:

enter image description here

However I get this:

enter image description here

I'm logging onto this server just as a regular user (not root or sudo) using PuTTY 0.60 and have set the following options under Window -> Colours:

Allow terminal to specify ANSI colours - checked
Allow terminal to use 256-colour mode - checked
Bolded test is a different colour - checked
Attempt to use logical palettes - unchecked
Use system colours - unchecked

If I sudo or logon as root and try the same I don't get any colours at all other than white text on a black background.

Are these schemes mostly aimed at gVIM and is PuTTY just not able to display these colours?

I've google'd around a bit and bumped into articles such as this one but they don't appear to work.


Solution 1:

By default, PuTTY presents itself as xterm. The terminfo database, used by various programs to determine the terminal capabilities, says xterm supports eight colors only:

$ infocmp -1L xterm | grep max_colors

This means that even if your version of Xterm does support 256-color mode, programs won't know about it.

  • The easiest fix is to set your $TERM environment variable to xterm-256color.

    (In your ~/.profile, you could use:
    if [ "$TERM" = xterm ]; then TERM=xterm-256color; fi)

  • You can tell PuTTY to always identify itself as xterm-256color, via Configuration → Connection → Data → Terminal-type string.

    Note: If you use #1 or #2, and you connect to a server which doesn't have the apropriate terminfo entry, all TUI programs will break.

  • You can also set the 't_Co' option in vim to 256 to override the terminfo value.

    if &term == "xterm"
        set t_Co=256
    endif
    
  • Or you could edit the terminfo database.

    $ infocmp -L -1 xterm | sed -r 's/(max_colors)#[0-9]+/\1#256/' > /tmp/xterm
    $ tic /tmp/xterm
    

    The updated entry will be kept in ~/.terminfo.