I may be wrong but I don't think you can give a decimal number as a value for the guifg
attribute (guifg=8
).
When I type :hi Tab gui=underline guifg=8 ctermbg=8
inside a terminal it works, but inside a gui, gvim returns the error message E254: Cannot allocate color8
.
Here's what the help says about this error (:help e254
) :
The color name {name} is unknown. See |gui-colors| for a list of
colors that are available on most systems.
And the help about gui-colors (:help gui-colors
) talks about color names, or hexadecimal values in the form of #rrggbb
(#rr
= red, #gg
=green, #bb
=blue).
But maybe I misunderstood something. Anyway, concerning your problem, here's what I would do.
Find a way to get the value of one of the attributes that I want to set.
For example, you want to give to the guifg
attribute of the Tab highlight group the value of 8. To get this value from a vim script you can use this expression :
synIDattr(hlID('Tab'), 'fg#')
Assign this value to a variable :
let guifgcolor=synIDattr(hlID('Tab'), 'fg#')
Write a function that tests the value of the variable. If it's not the one that I want (8 in this example), then execute the command hi Tab gui=underline guifg=8 ctermbg=8
and if it is then execute hi clear Tab
.
Write a mapping that calls the function.
It could give something like this :
function! ToggleHighlightGroup()
let guifgcolor=synIDattr(hlID('Tab'), 'fg#')
if guifgcolor == 8
highlight clear Tab
else
highlight Tab gui=underline guifg=8 ctermbg=8
endif
endfunction
nnoremap <F3> :<c-u>call ToggleHighlightGroup()<cr>
Edit : VanLaser suggests a good link that explains how to toggle an option in more details.