[英]vim scripting, if vim version is < 7.3
I was looking around for it for quite a while. 我在寻找它已有一段时间了。
I want to add a line to a vim plugin file that would disable it if running on unsupported version of vim. 我想在vim插件文件中添加一行,如果在不支持的vim版本上运行,将禁用它。
I remember from somewhere that it goes something like that: 我从某个地方记得它是这样的:
if version > 730
"plugin code goes here
endif
but that fail. 但那失败了。
The versioning scheme is different; 版本控制方案不同; Vim 7.3 is 703
, not 730
. Vim 7.3是703
,而不是730
。
Also, for clarity, I would recommend using v:version
(this is a special Vim variable). 另外,为了清楚起见,我建议使用v:version
(这是一个特殊的Vim变量)。
Often, it is also better to check for the availability of features ( eg exists('+relativenumber')
) than testing for the Vim version that introduced the feature, because Vim can be custom-compiled with different features. 通常,检查功能的可用性(例如, exists('+relativenumber')
)比测试引入该功能的Vim版本更好,因为Vim可以使用不同的功能进行自定义编译。
Finally, plugins typically do the guard the other way around: 最后,插件通常会以相反的方式保护:
if v:version < 703
finish
endif
" Plugin goes here.
And it's a good practice to combine this with an inclusion guard. 将此与包容性防守结合起来是一种很好的做法。 This allows individual users to disable a (system-wide) installed plugin: 这允许个人用户禁用(系统范围)安装的插件:
" Avoid installing twice or when in unsupported Vim version.
if exists('g:loaded_pluginname') || (v:version < 700)
finish
endif
let g:loaded_pluginname = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.