Vimscript - get colors programmatically from colorscheme
I am trying to create an autocmd in Vimscript that sets multiple colorscheme attributes the way I want them. In particular, I am trying to make the background NonText
the same color as the normal background.
The problem is I have no idea how to get the background color of the color scheme from vimscript.
Does anyone have any idea?
Edit:
So this is what I am trying to achieve. There are actually a few things:
-
Initially I tried to hide the "~" in front of all non-existent lines. Someone suggested to install it as the same color as the background, so I added the autorun, which made it:
hi NonText guifg=bg
. -
After that I realized that some colors have a different background color for regular lines and the "non-existent" part of the buffer. This is a problem as my autocmd sets the NonText color to be the same as a normal background, not a special "nonexistent" background.
Also, I figured that even without the whole "getting rid of the problem
~
" I didn't like it when the non-existent parts of the buffers had a different color.
Finally, I'm trying to learn about general vim schemas in general, as I'm planning on writing a plugin that will need other tricks like calculating colors from schemas.
source to share
There are two approaches here:
- Use
hi NonText
. Not alone, but with:redir
, of course. I will not describe this in more detail, because I personally do not like any solution using:redir
for a number of reasons (they: 1. requires parsing 2. no nested redirects 3. no way to know if a redirect is active). -
Use
synIDattr()
andhlID()
:let bgcolor=synIDattr(hlID('NonText'), 'bg#')
will assign something in the form
"#rrggbb"
(just"N"
in the terminal) to a variablebgcolor
or-1
if the background for this group is not defined. You can use this to build a team:hi
(regular background must be defined in the groupNormal
). -
Just use
hi link NonText Ignore
... Works unless your color scheme has overridden the group
Ignore
to actually appear.
source to share
hi NonText guibg=bg
How about this?
EDIT after clarification from OP:
Okey, let go from the start. At the moment, I am adding a plugin to hold the plugin several times until you know the basic settings and the Vim language. The symbols, one of which is the ~
one you are trying to hide, are so called list symbols and can be defined in an option listchars
. What you can see can be seen set listchars?
. They can also be turned on / off (visible or invisible, I mean) with set list
/ set nolist
, or to be turned on / off with set invlist
.
The selection group NonText
is the one that "covers" the display of these symbols, but in fact the way to turn them on or off is through a setting, not by overwriting the background / foreground color of that group. Therefore, my initial confusion is about your intentions. There is also a highlight group SpecialKey
that you may also find interesting as it covers some cases.
source to share