The question should be self-explanatory from the title, but to elaborate, should values that a Vim plugin allows users to set be defined as options or variables? I'm not quite sure what the difference is, or what the impact of using one over the other is.
问题应该从标题中不言自明,但要详细说明,Vim插件允许用户设置的值是否应该被定义为选项或变量?我不太确定它的区别是什么,或者使用一个相对于另一个的影响是什么。
1 个解决方案
#1
1
If by "options" you mean things like autoindent
or colorcolumn
, you can set
or unset
them and retrieve their value… but you can't create "options".
如果“选项”指的是像autoindent或colorcolumn这样的东西,你可以设置或取消设置它们并检索它们的值......但是你不能创建“选项”。
What you can use, though, are "internal variables" on which you can read all about in :help internal-variables
.
但是,您可以使用的是“内部变量”,您可以在其中阅读所有内容:help internal-variables。
Use global variables (g:var
) for the user-defined "options" of your plugin and script-local variables (s:var
) or function-local variables (l:var
or simply var
inside a function) in your script.
在脚本中使用全局变量(g:var)作为插件的用户定义“选项”和脚本局部变量(s:var)或函数局部变量(l:var或函数内的var)。
if !exists('g:myplugin_option')
let g:myplugin_option = 1
endif
#1
1
If by "options" you mean things like autoindent
or colorcolumn
, you can set
or unset
them and retrieve their value… but you can't create "options".
如果“选项”指的是像autoindent或colorcolumn这样的东西,你可以设置或取消设置它们并检索它们的值......但是你不能创建“选项”。
What you can use, though, are "internal variables" on which you can read all about in :help internal-variables
.
但是,您可以使用的是“内部变量”,您可以在其中阅读所有内容:help internal-variables。
Use global variables (g:var
) for the user-defined "options" of your plugin and script-local variables (s:var
) or function-local variables (l:var
or simply var
inside a function) in your script.
在脚本中使用全局变量(g:var)作为插件的用户定义“选项”和脚本局部变量(s:var)或函数局部变量(l:var或函数内的var)。
if !exists('g:myplugin_option')
let g:myplugin_option = 1
endif