首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将VIM中的语法高光颜色设置为语法脚本中的局部变量的值?

如何将VIM中的语法高光颜色设置为语法脚本中的局部变量的值?
EN

Stack Overflow用户
提问于 2012-01-06 00:03:24
回答 1查看 603关注 0票数 2

我想要做的事情如下所示:

代码语言:javascript
复制
"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语法脚本中完成吗?如果是这样的话,是怎么做的?

我已经尝试了几种变体:

代码语言:javascript
复制
"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

代码语言:javascript
复制
"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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-06 01:33:43

使用:exec,就像eval对于Perl或bash shell一样:

代码语言:javascript
复制
:exec 'hi cyLoops guifg=' . s:procedural_fg
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8745585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档