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

前端 未结 1 1198
野的像风
野的像风 2021-01-11 10:15

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!

相关标签:
1条回答
  • 2021-01-11 11:12

    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 讨论(0)
提交回复
热议问题