[已解决] 看来解决方法是这样的:
if exists('g:nameOfMyOption') && g:nameOfMyOption
...
endif
这很简单,但我在网上找不到答案。我想在插件文件中做这样的事情:
" MyChecker.vim
"
" Uncomment the following line to set the autochecker option
"set autochecker=1
if ISSET(autochecker)
autocmd InsertChange * :call MyAutoCheckerFunction()
endif
我如何做 ISSET 线?我宁愿不必显式设置 autochecker=0,我希望它只检查 autochecker 是否存在。
编辑:当我尝试以下操作时:
if &autochecker == 1
...
endif
我收到此错误消息:
Error detected while processing MyChecker.vim:
line 32:
E113: Unknown option: autochecker
E15: Invalid expression: &autochecker == 1
最佳答案
您不能在 vim 中创建自定义选项。您需要创建一个全局变量,而不是:
let g:AutoChecker = 1
....
if g:AutoChecker == 1
" ...
endif
关于options - 编写vimscript时如何使用选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10016039/