我想做的事情如下:
"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
但是VIM不允许我这样设置guifg值(“错误:不能为每个变量名称分配颜色s:procedural_fg”......等等)。我想定义以这种方式突出显示的语法,以便可以通过更改局部变量值然后刷新缓冲区(或者应用新颜色值所需的任何内容)来动态更改它。
这可以在VIM语法脚本中完成吗?如果是这样,怎么样?
我已经尝试了几种变体:
"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
和
"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
导致出错,抱怨Red,Blue等或v:Red,v:Blue等未定义和/或表达无效。
感谢, CCJ
答案 0 :(得分:2)
使用:exec
,这对于Vim来说是eval
对于Perl或bash shell:
:exec 'hi cyLoops guifg=' . s:procedural_fg