Vim Tips Wiki

Using vim color schemes with Putty

1,625pages on
this wiki
Add New Page
Talk0 Share
Tip 1576 Printable Monobook Previous Next

created 2008 · complexity basic · author Timkebox · version 7.0

I am using PuTTY in Windows to access a Unix box, and the Terminal-type string in PuTTY is set to xterm. I wanted to use Vim's color schemes. I tried many different things with no decent result until I found the following code in Vim's help. After inserting the following lines in my vimrc, I was able to use all the color schemes defined by Vim.

For a 16-color display:

if has("terminfo")
  let &t_Co=16
  let &t_AB="\<Esc>[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm"
  let &t_AF="\<Esc>[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm"
  let &t_Co=16
  let &t_Sf="\<Esc>[3%dm"
  let &t_Sb="\<Esc>[4%dm"

:help xfree-xterm

For an 8-color display:

if &term =~ "xterm"
  if has("terminfo")
    let &t_Co=8
    let &t_Sf="\<Esc>[3%p1%dm"
    let &t_Sb="\<Esc>[4%p1%dm"
    let &t_Co=8
    let &t_Sf="\<Esc>[3%dm"
    let &t_Sb="\<Esc>[4%dm"


With the settings below, using :runtime syntax/colortest.vim shows all 23 colors as distinctly unique.

Putty settings: Window, Colours

[x] Allow terminal to specify ANSI colours
[x] Allow terminal to specify xterm 256-colour mode
[x] Bolded text is a different colour

Settings in vimrc:

if &term =~ "xterm"
  " 256 colors
  let &t_Co = 256
  " restore screen after quitting
  let &t_ti = "\<Esc>7\<Esc>[r\<Esc>[?47h"
  let &t_te = "\<Esc>[?47l\<Esc>8"
  if has("terminfo")
    let &t_Sf = "\<Esc>[3%p1%dm"
    let &t_Sb = "\<Esc>[4%p1%dm"
    let &t_Sf = "\<Esc>[3%dm"
    let &t_Sb = "\<Esc>[4%dm"

See alsoEdit


It is relatively easy to change the TERM setting PuTTY uses to set it to send it as "xterm-256color" (or install the full set of terminfo files and set it to the proper setting of "putty-256color". -- PuTTY doesn't support Techtronix mode and so is not fully xterm compatible.)

In PuTTY this is changed in the Configuration in the Connection -> Data section. This is the same preferences page where you specify your auto-login username, so you should be visiting this page anyway. With your auto-login username specified, and public key authorization (which you should be using) and a key agent running (PuTTY's Pageant does this) you can select a host and log in without being prompted for username or password.

With your TERM set to anything close to accurate, you can then leverage all 256 colors in other applications without manually tweaking the settings for every application.

Steven Black 17:49, December 9, 2010 (UTC)

I often use PuTTY at work to connect to a solaris box which we use for compiling code. I have no admin rights, and no knowledge of how to set up terminfo, etc. I tried the PuTTY setting you give, but I just get a "using dumb terminal mode" message on login, and Vim has no colors. The 256-color workaround in this tip works fine. I don't like it, I'd rather do it "the right way" but sadly this may not be an option for me. Unless there's something I can do in my own user space to get the terminfo correct. --Fritzophrenic 19:28, December 9, 2010 (UTC)

Chances are your system doesn't use terminfo then. Try hardwiring your term option like this:

set term=builtin_xterm


set term=builtin_ansi

That should give you colors in putty. Your vim needs to be compiled with +builtin_term (+ or ++), though.

Chrisbra 20:50, December 9, 2010 (UTC)

Thanks for the suggestion. I have +builtin_terms (not ++builtin_terms) but neither :set term=builtin_xterm nor :set term=builtin_ansi have any noticeable effect to enable colors, even when it is the first item in the .vimrc (after :set nocompatible). Since the hack in this tip does work for me, and I really don't know much about terminal configuration, I'm probably going to just leave it. --Fritzophrenic 14:24, December 10, 2010 (UTC)

It works for me with putty. But I need to explicitly set :syntax on after setting 'term' to builtin_ansi. 13:20, December 11, 2010 (UTC)

Try to set Terminal-type string in putty (Connection->Data) to 'putty-256color'. That worked for me.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.