How to get terminal fg/bg colors

47 views
Skip to first unread message

Jeremy Brubaker

unread,
Dec 1, 2021, 3:47:29 PM12/1/21
to
I am trying to get the fore- and background colors of my terminal in my
.vimrc. I found the /t_RB/ and /t_RF/ options in the manual, but either
they don't work or I'm not using them properly (likely the latter).

I tried `set t_RB` and then `echomsg v:termrbgresp` and just got an
empty string. Do I need to set /t_RB/ to something specific for this to
work?

For context, I'm trying to create some functions that will set some UI
colors based on my terminal background color. Specifically /CursorLine/
right now.

--
() www.asciiribbon.org | Jeremy Brubaker
/\ - against html mail | јЬruЬаkе@оrіоnаrtѕ.іо / neonrex on IRC

Dry clean only.

Eli the Bearded

unread,
Dec 5, 2021, 12:58:03 AM12/5/21
to
In comp.editors, Jeremy Brubaker <jbruba...@orionarts.invalid> wrote:
> I am trying to get the fore- and background colors of my terminal in my
> .vimrc. I found the /t_RB/ and /t_RF/ options in the manual, but either
> they don't work or I'm not using them properly (likely the latter).
>
> I tried `set t_RB` and then `echomsg v:termrbgresp` and just got an
> empty string. Do I need to set /t_RB/ to something specific for this to
> work?

The only reason to assign values to the t_?? settings is to "correct"
(often correct is more opinion than fact) the terminal settings. I have
in my .vimrc:

" t_Co number of colors supported by the terminal
set t_Co=0

and if I try ":set t_RB?" I get back an empty string. Testing by
commenting that setting out, I get color in vim, but still see t_RB as
empty here (version 8.2.3615 on NetBSD in an xterm, but TERM set to
"screen"). Trying on Linux, version 8.1.2269, same version xterm, but
TERM set to xterm, I do get a value for RB:

:set t_RB?
t_RB=^[]11;?^G

> For context, I'm trying to create some functions that will set some UI
> colors based on my terminal background color. Specifically /CursorLine/
> right now.

I find white on black is best, so I don't really have experience to help
debug colors in vim. Have you tried the vim mailling list? ":help vim-use"
Joining the list and using the subscriber posting address is faster, but
the address in the help works.

I also set t_TI and t_TE to empty strings (start and stop of raw mode)
and used to use a t_ setting for mouse, but I've found "set ttym=" to
be more what I want.

Back when I was using actual terminals, instead of xterms always, I had
more opinions about termcap/terminfo settings. I've forgotten many of the
details.

vi is one of the oldest terminal oriented programs, and these t_??
options date back to the late 1970s, early 1980s. Early vi used very few
of them. ex-1.1, first to include a "visual" mode about a donzel calls
to a tget(num|flag|str) family function in the source.

Elijah
------
has a compiled version of ex-1.1 and has used it briefly

Jeremy Brubaker

unread,
Dec 8, 2021, 3:43:23 PM12/8/21
to
On 2021-12-05, Eli the Bearded wrote:
> In comp.editors, Jeremy Brubaker <jbruba...@orionarts.invalid> wrote:
>> I am trying to get the fore- and background colors of my terminal in my
>> .vimrc. I found the /t_RB/ and /t_RF/ options in the manual, but either
>> they don't work or I'm not using them properly (likely the latter).
>>
>> I tried `set t_RB` and then `echomsg v:termrbgresp` and just got an
>> empty string. Do I need to set /t_RB/ to something specific for this to
>> work?
>
> "screen"). Trying on Linux, version 8.1.2269, same version xterm, but
> TERM set to xterm, I do get a value for RB:
>
> :set t_RB?
> t_RB=^[]11;?^G

If I have TERM set to xterm* then t_RB=^[]11;?^G. If TERM is st* then
t_RB is empty. It's also empty when I run vim inside tmux, regardless of
the underlying value of TERM.

But v:termr{b,f}gresp are empty if t_R{B,F} is set automatically or if I
set it in .vimrc.

--
() www.asciiribbon.org | Jeremy Brubaker
/\ - against html mail | јЬruЬаkе@оrіоnаrtѕ.іо / neonrex on IRC

What causes the mysterious death of everyone?
Reply all
Reply to author
Forward
0 new messages