18

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.

1 Answer 1

28

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.

9
  • 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
    Sep 14, 2011 at 14:44
  • 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. Sep 14, 2011 at 14:47
  • 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.) Sep 14, 2011 at 16:09
  • 1
    vi --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
    Sep 14, 2011 at 16:19
  • 1
    Sort 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...) Sep 14, 2011 at 16:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .