1

I'm trying to make a colorscheme configurable where I define the style in a variable defined in my .vimrc.

let g:plugin_style='<vim-highlighting-style>'

Then in the colorscheme I'm doing:

highlight! StyleName g:plugin_style

This doesn't work, hightlight! uses the literal g:plugin_style.

I tried as well to use exec

exec 'highlight! StyleName ' . g:plugin_style

This doesn't work neither, StyleName is not known afterwards.

How to do this in vimscript?

  • This answer seems to indicate that you can use the exec syntax. I may be wrong but I guess the problem comes from the fact you define your variable after setting your colorscheme? Also I guess it's a typo but your definition line should be let g:plugin_style='VirtualNOS' – statox Oct 24 '16 at 8:33
  • Also I'm not a colorscheme expert but are you sure that highlight! StyleName VirtualNOS makes sense? Shouldn't it be something of the form highlight! StyleName term=bold ctermfg=Cyan guifg=#80a0ff gui=bold? – statox Oct 24 '16 at 8:40
  • 2
    The less "logic" you put in your colorscheme the better it will work. – romainl Oct 24 '16 at 9:39
  • I asked this question for the HighlightCursorWords-plugin (github.com/pboettch/vim-highlight-cursor-words). Which creates a new style for itself which should be configurable from .vimrc. – Patrick B. Oct 25 '16 at 7:34
1

As @Jamessan suggested in this SO answer, using execute should work properly.

Firs the variable should be defined like this:

let g:plugin_style='term=bold ctermfg=Cyan guifg=#80a0ff gui=bold'

See :h highlight-args for the values that this variable can take.

Then simply use:

execute 'highlight [default] {group-name} ' . g:plugin_style

Finally an important note is to define the variable before you call your colorscheme otherwise the colorscheme cannot know the value of the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.