I'm trying to create an autocmd in Vimscript which sets a few attributes of the colorscheme as I want them. Specifically, I'm trying to make the NonText
background have the same color as the regular background.
The problem is, I have no idea how to get a colorscheme's background color from within vimscript.
Anyone have any ideas?
Edit:
So here's what I'm trying to achieve. Actually a few things:
Originally, I was trying to hide the "~" that's in front of all non-existant lines. Someone suggested setting it as the same color as the background, so I added an autocmd that did this: hi NonText guifg=bg
.
After doing that, I realized that some colorschems have a different background color for the regular lines and the "non-existant" part of the buffer. This is a problem, since my autocmd sets the NonText color to be the same as the regular background, not the special "non-existant" background.
Also, I decided that even without the whole "get rid of the ~
" issue, I don't like it when the non-existant parts of buffers are a different color.
Lastly, I'm trying to learn about vim colorschemes in general, since I'm planning to write a plugin that will need some other tricks like figuring out the colors from schemes.
There are two approaches here:
hi NonText
. Not alone, but with :redir
, of course. I won’t describe it more verbose because I personally don’t like any solution using :redir
for a number of reasons (they are: 1. requires parsing 2. no nested redirections 3. no way to know whether redirection is active).Use synIDattr()
and hlID()
:
let bgcolor=synIDattr(hlID('NonText'), 'bg#')
will assign something in form "#rrggbb"
(just "N"
in terminal) to variable bgcolor
, or -1
if background was not defined for this group. You can use this to construct :hi
command (regular background should be defined in Normal
group).
Just use
hi link NonText Ignore
. Works unless your colorscheme has redefined Ignore
group so that it actually is shown.
hi NonText guibg=bg
How about that?
EDIT after clarification from the OP:
Okey, let's go from the start. For now I'd put writing of a plugin on hold for a while until you get acquinted with the basic Vim settings and language. The characters, one of which is the ~
you're trying to hide, are so called list characters, and they can be defined in the listchars
option. What yours are you can see by set listchars?
. They can also be turned on/off (visible or invisible, I mean) by either set list
/ set nolist
, or toggled on/off with set invlist
.
The NonText
highlighting group is the one that "covers" the display of those characters, but really the way to turn them on/off is via the setting, not via overwriting the background/foreground color of that group. Therefore my original confusion over your intentions. There is also a highlighting group SpecialKey
that you might also find interesting, since it cover some cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With