Vimscript:使用 vim 设置作为变量/如何检查是否设置了特定的 guioption [英] Vimscript: use vim settings as variables / How to check if specific guioption is set or not
问题描述
我想在 gvim 中创建一个切换功能,可以打开/关闭滚动条和换行选项.
I want to make a toggle function in gvim that would turn on/off scrollbar and wrap option.
切换换行选项没有问题.我只是使用 set wrap!
.要更改水平滚动条设置,我需要检查 wrap
选项或 guioptions
的值.
There is no problem for toggling wrap option. I simply use set wrap!
.
To change horizontal scrollbar setting I need to check the value of wrap
option or guioptions
.
问题是如何读取wrap
或guioptions
的值?你还有其他热门歌曲吗?
The question is how to read value of wrap
or guioptions
? Do you have some other hits?
推荐答案
您可以使用 &setting
来访问 vim 设置的值.参见:help expr-option
.
You can use &setting
to access the value of a vim setting. See :help expr-option
.
在这里你可以这样做:
if &guioptions =~# 'a'
....
endif
=~#
in vimscript 做区分大小写的正则表达式匹配.
=~#
in vimscript does case-sensitive regex matching.
同样,如果你想检查一个选项是否未设置,
Similarly, if you wanted to check if an option is not set,
if &guioptions !~# 'a'
....
endif
如果您想临时保存设置:
If you want to temporary save a setting:
let oldwrap=&wrap
set nowrap
... (your script assuming nowrap)
let &wrap=oldwrap
unlet oldwrap
这篇关于Vimscript:使用 vim 设置作为变量/如何检查是否设置了特定的 guioption的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!