Search code examples
vim

How to use options when writing vimscript?


It's very straightforward, but I can't find the answer online. I want to do something like this in a plugin file:

" MyChecker.vim
"
" Uncomment the following line to set the autochecker option
"set autochecker=1

if ISSET(autochecker)
   autocmd InsertChange * :call MyAutoCheckerFunction()
endif

How do I do the ISSET line? I'd rather not have to explicitly set autochecker=0, I'd like it to just check if autochecker exists.

Edit: When I try the following:

if &autochecker == 1
    ...
endif

I get this error message:

Error detected while processing MyChecker.vim:
line   32:
E113: Unknown option: autochecker
E15: Invalid expression: &autochecker == 1

Solution

  • You can't create custom options in vim. You need to create a global variable instead like:

    let g:AutoChecker = 1
    
    ....
    
    if g:AutoChecker == 1
       " ...
    endif