开发者

Vimscript: use vim settings as variables / How to check if specific guioption is set or not

开发者 https://www.devze.com 2023-02-16 20:37 出处:网络
I want to make a toggle function in gvim that would turn on/off scrollbar and wrap option. There is no problem for toggling wrap option. I simply use set wrap!.

I want to make a toggle function in gvim that would turn on/off scrollbar and wrap option.

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 开发者_JAVA百科option or guioptions.

The question is how to read value of wrap or guioptions? Do you have some other hits?


You can use &setting to access the value of a vim setting. See :help expr-option.

Here you can thus do:

if &guioptions =~# 'a'
   ....
endif

=~# 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
0

精彩评论

暂无评论...
验证码 换一张
取 消