Custom highlight color outside the 16-set cterm palette?

36 views
Skip to first unread message

Steven H.

unread,
Apr 16, 2025, 4:02:20 AMApr 16
to v...@vim.org
Hi,

I am using xfce4-terminal and xterm.

I would like to highlight tab indents with a custom color, which is not
in the 16-set cterm palette.

Currently I have:

highlight SpecialKey ctermfg=grey ctermbg=black

I would like to use '#222222' instead of 'black' for background
*without* that affecting any other color in the color scheme.

How can I do that?

dva...@internode.on.net

unread,
Apr 16, 2025, 5:10:17 AMApr 16
to vim...@googlegroups.com
On 16.04.25 08:01, Steven H. wrote:
> I would like to use '#222222' instead of 'black' for background
> *without* that affecting any other color in the color scheme.
>
> How can I do that?

For nearly 40 years now, I've used the multitudinous *term colours,
which remain in effect in vi/vim, mutt, etc. In that time, I've stuck
with:

   -fg yellow -bg darkslategrey -cr red

as it's very restful on the eyes, and a simple way to set the
background colour.

There's 754 colours in my /etc/X11/rgb.txt, but 782 in
/usr/share/vim/vim81/rgb.txt , maybe more in a more current version. And I guess you could add your own, if needed.

But I change the cursor colour in vim, using its limited palette, to
differentiate insert vs normal mode at the cursor, not just the status
line.

"MODE-INDICATING TRICOLOUR CURSOR:
"Appearance: (Insert_Mode = Red, Replace Mode = Purple, Normal_Mode = Green)
if &term =~ "xterm"
   let &t_SI = "\<Esc>]12;red\x7"
   let &t_SR = "\<Esc>]12;purple\x7"
   let &t_EI = "\<Esc>]12;green\x7"
endif

Admittedly, it's not tested with every terminal variant out there. Now that xterms support utf8, I've no need for odd ones.

Erik

Steven H.

unread,
Apr 16, 2025, 12:47:16 PMApr 16
to v...@vim.org
On Wed, 16 Apr 2025 09:10:05 +0000 dvalin via vim_use wrote:

> There's 754 colours in my /etc/X11/rgb.txt, but 782 in
> /usr/share/vim/vim81/rgb.txt , maybe more in a more current version.

Here:

find /usr/share/vim/ -name 'rgb.txt'

shows me nothing.

> And I guess you could add your own, if needed.
> But I change the cursor colour in vim, using its limited palette, to
> differentiate insert vs normal mode at the cursor, not just the status
> line.
>
> "MODE-INDICATING TRICOLOUR CURSOR:
>
> "Appearance: (Insert_Mode = Red, Replace Mode = Purple, Normal_Mode = Green)
>
> if &term =~ "xterm"
> let &t_SI = "\<Esc>]12;red\x7"
> let &t_SR = "\<Esc>]12;purple\x7"
> let &t_EI = "\<Esc>]12;green\x7"
> endif

where do I type this? And how does it affect the color of tab indents?

I hope you can clarify. I am not an expert.
FWIW, I am using desert colorscheme.

Steven H.

unread,
Apr 16, 2025, 12:48:44 PMApr 16
to v...@vim.org
P.S. In case it is not clear (as I didn't say that explicitly), my
question is about VIM.

Christian Brabandt

unread,
Apr 16, 2025, 1:39:09 PMApr 16
to vim...@googlegroups.com

On Wed, 16 Apr 2025, Steven H. wrote:

> On Wed, 16 Apr 2025 09:10:05 +0000 dvalin via vim_use wrote:
> > There's 754 colours in my /etc/X11/rgb.txt, but 782 in
> > /usr/share/vim/vim81/rgb.txt , maybe more in a more current version.

That is outdated

>
> Here:
>
> find /usr/share/vim/ -name 'rgb.txt'
>
> shows me nothing.

rgb.txt has been removed with patch v8.2.376 once the colors list became
available with patch v8.2.3562

I would check the v:colornames dictionary, see :h v:colornames.

If you have a recent terminal, chances are you can use rgb color names
directly by :set termguicolors and then setting the guifg/guibg color
names directly. See :h xterm-true-color

Best,
Christian
--
Laugh at your problems; everybody else does.

Arun E

unread,
Apr 16, 2025, 3:28:23 PMApr 16
to vim...@googlegroups.com
On Wed, Apr 16, 2025 at 10:39 AM Christian Brabandt <cbl...@256bit.org> wrote:

If you have a recent terminal, chances are you can use rgb color names
directly by :set termguicolors and then setting the guifg/guibg color
names directly. See :h xterm-true-color


This is pretty amazing, makes my vim terminal windows so much more colorful in iterm2. Thanks Christian for the tip.

dva...@internode.on.net

unread,
Apr 16, 2025, 7:28:25 PMApr 16
to vim...@googlegroups.com
On 16.04.25 16:48, Steven H. wrote:
> P.S. In case it is not clear (as I didn't say that explicitly), my
> question is about VIM.

It was eminently evident. My reply included "vi/vim, mutt, etc.", intending to
make the point that setting bg/fg colours in the terminal provides consistency
across apps. (I'm too lazy to want to find ways to do it individually in each.)

On 16.04.25 16:46, Steven H. wrote:
> On Wed, 16 Apr 2025 09:10:05 +0000 dvalin via vim_use wrote:
>
> > There's 754 colours in my /etc/X11/rgb.txt, but 782 in
> > /usr/share/vim/vim81/rgb.txt , maybe more in a more current version.
>
> Here:
> find /usr/share/vim/ -name 'rgb.txt'
> shows me nothing.
>
> > And I guess you could add your own, if needed.
> > But I change the cursor colour in vim, using its limited palette, to
> > differentiate insert vs normal mode at the cursor, not just the status line.

Here,
$ locate rgb.txt
also shows:
/etc/X11/rgb.txt
/usr/share/X11/rgb.txt

They're the system version - all that's needed. I see there:
222 222 222       gray87
222 222 222       grey87
so: xterm -bg grey87
should do the trick, without further ado.

> > "MODE-INDICATING TRICOLOUR CURSOR:
> > "Appearance: (Insert_Mode = Red, Replace Mode = Purple, Normal_Mode = Green)
> >
> > if &term =~ "xterm"
> > let &t_SI = "\<Esc>]12;red\x7"
> > let &t_SR = "\<Esc>]12;purple\x7"
> > let &t_EI = "\<Esc>]12;green\x7"
> > endif
>
> where do I type this? And how does it affect the color of tab indents?
>
> I hope you can clarify. I am not an expert.
> FWIW, I am using desert colorscheme.

It goes into your ~/.vimrc
and has no observable effect on tabs.
To distinguish tabs from spaces, e.g. in makefiles, I place the modeline:
# vim:noexpandtab list
in the file. The desired representation for tabs and trailing whitespace
is set by:
set listchars=tab:>-,trail:-
also in ~/.vimrc

Vim's "help listchars" provides more options there than any one person
could find a use for, I think.

Hope that helps set the required appearance. If you use vim for
everything, then it's important to have restful colours, as you're
setting up.

Apropos "desert" I notice in rgb.txt :

244 164  96    sandy brown
244 164  96    SandyBrown

The closest to desert that I've used is a less glaring background for my
preferred pdf viewer:

/usr/bin/xpdf -geometry 1200x900+5+0 -z width -papercolor wheat3 $fn &

(I've put that in a shell function which first converts spaces in the
filename to '_', as xpdf borks on that. But that's not directly relevant
here.)

Erik

Romain Lafourcade

unread,
Apr 17, 2025, 1:13:01 AMApr 17
to vim_use
Both xfce-terminal and xterm support 256 colors.
In both cases, the $TERM variable environment must be set to `xterm-256color` for Vim to configure itself properly during startup.
This allows you to use any of the 256 colors in the following palette:

The closest to #222222 is 235, which gives you:

highlight SpecialKey ctermfg=235 ctermbg=black

Making use of "true colors" is also possible if your versions of xfce-terminal and xterm support it (>0.6.90 and >331, respectively). See :help xterm-true-color.

Steven H.

unread,
Apr 17, 2025, 10:32:54 AMApr 17
to v...@vim.org
Thanks everyone!

On Wed, 16 Apr 2025 22:13:00 -0700 (PDT) Romain Lafourcade wrote:

> highlight SpecialKey ctermfg=235 ctermbg=black

This is what worked fine for me and what I was looking for:

highlight SpecialKey ctermfg=grey ctermbg=234

Is there a way to "give priority" to the color of the CursorLine?
Currently I have:

highlight CursorLine ctermbg=Black ctermfg=none

However, when the cursor is on a line containing a "tab", the tab
"takes priority" and the part of the line is not fully on black
background (as per CursorLine config).

What determines which is prioritized and how can one control that?
Reply all
Reply to author
Forward
0 new messages