What I’d like to do is something like the following:
"define our language struct variables with their default syntax color values
let s:procedural_fg = "Red"
let s:declarative_fg = "Blue"
let s:string_fg = "DarkGray"
...
"Now the actual highlighting directives based on the groups defined elsewhere
hi cyLoops guifg=s:procedural_fg
hi cyConstants guifg=s:declarative_fg
hi cyString guifg=s:string_fg
but VIM won’t let me set the guifg values this way (“Error: Cannot allocate color s:procedural_fg” … and so forth for each variable name). I’d like to define the syntax highlighting this way so that it can be dynamically altered by changing the local variable values and then refreshing the buffer (or whatever it would take to make the new color values apply).
Can this be done in a VIM syntax script? If so, how?
I’ve already tried several variations:
"define our language struct variables with their default syntax color values
let s:procedural_fg = Red
let s:declarative_fg = Blue
let s:string_fg = DarkGray
...
"Now the actual highlighting directives based on the groups defined elsewhere
hi cyLoops guifg=s:procedural_fg
hi cyConstants guifg=s:declarative_fg
hi cyString guifg=s:string_fg
and
"define our language struct variables with their default syntax color values
let s:procedural_fg = v:Red
let s:declarative_fg = v:Blue
let s:string_fg = v:DarkGray
...
"Now the actual highlighting directives based on the groups defined elsewhere
hi cyLoops guifg=s:procedural_fg
hi cyConstants guifg=s:declarative_fg
hi cyString guifg=s:string_fg
which leads to an error complaining that Red, Blue etc. or v:Red, v:Blue etc. are undefined and/or invalid expressions.
thanks,
CCJ
Use
:exec, which is to Vim whatevalis to Perl or bash shell: