[SOLVED] It seems the solution is this:
if exists('g:nameOfMyOption') && g:nameOfMyOption
...
endif
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
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
For general options, I use the following function: lh#option#get().
It first searches if b:{varname}
exists to return its value, then g:{varname}
. Otherwise the default value provided is returned if none of the variables exist.
For programming related options (i.e. options can can be overridden for specific filetypes), I use another function: lh#dev#option#get().
The C++ Options section of lh-cpp documentation indirectly explains the rationale behind these two functions.