vim scripting, if vim version is < 7.3

GoTTimw picture GoTTimw · Aug 2, 2012 · Viewed 7.8k times · Source

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.

I remember from somewhere that it goes something like that:

if version > 730
    "plugin code goes here
endif

but that fail.

Answer

Ingo Karkat picture Ingo Karkat · Aug 2, 2012

The versioning scheme is different; Vim 7.3 is 703, not 730.

Also, for clarity, I would recommend using v:version (this is a special Vim variable).

Often, it is also better to check for the availability of features ( e.g. exists('+relativenumber')) than testing for the Vim version that introduced the feature, because Vim can be custom-compiled with different features.

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