Using colour schemes with vim and putty

16

10

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.

Kev

Posted 2011-09-14T12:41:02.650

Reputation: 1 922

Answers

23

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.

user1686

Posted 2011-09-14T12:41:02.650

Reputation: 283 655

Excellent answer. It's better, but I have feeling 256 colours isn't enough to render these pastel shades. Any idea why I don't get any colours at all when logged in as root? – Kev – 2011-09-14T14:44:51.527

1@Kev: 1) 256-color mode is the best you can get on a VT100-compatible terminal emulator. (I heard KDE Konsole having true-color support, but it's very much nonstandard.) 2) When you log in as root, you get a separate home directory, and a separate ~/.vim/colors as well. – user1686 – 2011-09-14T14:47:24.360

I have the color scheme in ~/.vim/colors but it seems to be ignored. I know vim can see it because if I do :colors for a scheme that isn't there it reports E185: Cannot find color scheme blahblahblah whereas no error when I do :colors desert. – Kev – 2011-09-14T14:50:35.027

@Kev: Hm. Do you have syntax highlighting enabled? (:syn on) How about $TERM - is it set to a sane value? – user1686 – 2011-09-14T14:52:33.387

Hmm...colours and syntax highlighting work with vim launched as root but not vi. I can live with that I guess. – Kev – 2011-09-14T15:18:08.220

1@Kev: Because vi does not have color schemes or syntax highlighting - or anything except the original basic features. (Vim is "Vi Improved" after all.) – user1686 – 2011-09-14T16:09:32.977

1vi --version says it's vim, so is it a cut back vim to make it look like vi? Sorry if that's a daft question, it's been years since I worked with unix in anger (SCO Unix boxes with serial ports) and there was only vi (real vi). – Kev – 2011-09-14T16:19:39.950

1Sort of. When you run vim as "vi", it starts in a "compatibility" mode, behaving as much as possible like vi. I don't know CentOS, so I'm not sure if it is just a mode, or an entirely separate trimmed-down build. (My distro packages the real vi instead...) – user1686 – 2011-09-14T16:58:01.087