[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: vim + termcaps + colors



On Tue, 7 Oct 2003, Monique Y. Herman wrote:

> Yet again I come to the group for support ...
>
> Okay, so, I get pretty colors when I run vim from within screen, both
> through putty and on the console itself.  When I run vim directly on
> putty or on the console, though, the only syntax highlighting is through
> bold.
>
> I'm guessing the difference is that screen sets TERMCAP.  This guess is
> reinforced by the fact that su -'ing to root from screen also loses
> colors (and of course loses the TERMCAP setting).

I just fought much the same battle: on my primary OS X machine, I could
get all the color I wanted (on my OS X machine or ssh'd into my Linux
box), I got just the bolding.

First, I found upgrading to a snapshot version of PuTTY helped somewhat.
You might test that.

Here's what I ended up doing. The key, apparently, is a couple of escape
sequences. Now, I still don't fully understand this, but it's working
reliably with my setups, giving me full color whether I'm on the
console, coming in through PuTTY (emulating xterm) or coming in through
Terminal.app (also sorta emulating xterm).

I ended up with this in my .vimrc (improvements gratefully requested):


if has("terminfo")
        if &term =~ "xterm"
                let s:color = "true"
                set t_Co=16
        elseif &term =~ "linux"
                let s:color = "true"
                set t_Co=16
        elseif &term =~ "vt220"
                let s:color = "true"
                set t_Co=8
        endif

        if exists("s:color")
                set t_Sf=<Esc>[3%dm
                set t_Sb=<Esc>[4%dm
        endif
endif

The t_Co sets the number of colors your terminal supports. xterm and the
linux console do 16 colors. The vt220 is how my OpenBSD console
identifies itself, and it doesn't work with 16, so I set it to 8
instead. The t_Sf and the t_Sb set the escape sequences to send to set
the foreground and background colors, respectively. All characters are
literal; it's should be safe to copy/paste this, and it should work fine
in Vim 6.

A couple things I do not understand: there are also codes t_AF and t_AB,
that seem to have the same purpose as t_Sf and t_Sb. I don't really
understand the distinction between them. termcap(5) didn't help much,
I'm afraid. t_Sf and t_Sb work for me, so I use them.

> [rest snipped]

I hope this is somewhat helpful.

- Aaron

-- 
Aaron Hall           :     Preliminary operational tests were inconclusive.
ahall@vitaphone.net  :     (The damn thing blew up.)



Reply to: