14

In Vimscript, how can I check the current value of a Vim option?

To elaborate, I want to make a command to switch from Full-GUI Mode ( guioptions=+tM) to Hacker Mode (guioptions=-tM).

However, I can't seem to find a way to parse the :set guioptions? value

13

You can use the &{option-name} in an if-statement like so:

if &guioptions ==# "Trl"
    echo "Toolbars and scrollbars are present!"
elseif &guioptions ==# ""
    echo "No toolbars and scrollbars present!"
endif

The & specifies that the variable name is a Vim option.

See :help :let-& for the full documentation.

3

Akshay solved it: Just posting the resulting function case other people might need / want it.

function! ToggleMenuBar()
    let l:menu_option = strridx(&guioptions, "m")
    let l:toolbar_option = strridx(&guioptions, "T")
    if l:menu_option > 0
        set guioptions-=m
    else
        set guioptions+=m
    endif
    if l:toolbar_option > 0
        set guioptions-=T
    else
        set guioptions+=T
    endif
endfunction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.