Using vim color schemes with Putty
From Vim Tips Wiki
Tip 1576 Previous Next created June 29, 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"
else
let &t_Co=16
let &t_Sf="\<Esc>[3%dm"
let &t_Sb="\<Esc>[4%dm"
endif
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"
else
let &t_Co=8
let &t_Sf="\<Esc>[3%dm"
let &t_Sb="\<Esc>[4%dm"
endif
endif
[edit] Alternative
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 color --
let &t_Co=256
" restore screen after quitting
set t_ti=ESC7ESC[rESC[?47h t_te=ESC[?47lESC8
if has("terminfo")
let &t_Sf="\ESC[3%p1%dm"
let &t_Sb="\ESC[4%p1%dm"
else
let &t_Sf="\ESC[3%dm"
let &t_Sb="\ESC[4%dm"
endif
endif
