I can check vim's version by using v:version
,
and I can check if I am running in nvim by doing has('nvim')
. Is there a variable like v:version
in neovim to let me know the nvim version, like 0.1.4
or 0.1.6
?
3 Answers
As mentioned in comments elsewhere, you can use has
. For generic "is this neovim":
:echo has('nvim')
For at least minor version 0.1
(latest as of this writing):
:echo has('nvim-0.1')
For at least patch version 0.1.6
:
:echo has('nvim-0.1.6')
There is probably a direct way (?); if not, here's a function that parses :version
to extract and return the actual value (as string):
function! GetNVimVersion()
redir => s
silent! version
redir END
return matchstr(s, 'NVIM v\zs[^\n]*')
endfunction
.. so that you can show it with: echo GetNVimVersion()
or store it in some variable.
-
5Actually, with
execute()
, this can be more compact:let version = matchstr(execute('version'), 'NVIM v\zs[^\n]*')
. But, the function was added in nvim 0.1.5 and vim 7.4.2008– Tommy AOct 18, 2016 at 1:35 -
That's good to know, thanks! Although a little ironic in this case - since the version isn't known, adding another branch for this situation -
if exists('*execute')
- actually makes the code bigger (since you can't rely on the function to exist in your (n)vim - for some time, at least).– VanLaserOct 18, 2016 at 9:00 -
From what I noticed, Neovim users tend to upgrade to the latest stable release since they're responsible for accessing distribution channels. Once it's in official package repositories, the problem you mentioned will be a more concrete reality when a version is frozen for a stable OS release. If I'm reading it right, Neovim 0.1.5 will be available in Debian Stretch.– Tommy AOct 18, 2016 at 13:37
-
Sure, if I'd need the version number myself, I'd certainly use your
execute()
-based one liner (because I know what I install).– VanLaserOct 18, 2016 at 20:22 -
It was just a thought about figuring out a baseline version if you really had to. The point is moot since the only good reason you'd want to get the version is to print it. I think there are better ways to test capabilities as I mentioned in the OP.– Tommy AOct 19, 2016 at 5:33
If you really want to get the version, instead of just checking if the editor is a specific patch, just use v:lua.vim.version()
. That is a special variable that can call into the Lua scripting functions, and just returns a Dictionary (vimscript's associative array). Use :echo v:lua.vim.version()
in command mode to see its values.
Example use:
if v:lua.vim.version().major == 0 && v:lua.vim.version().minor < 8
" Run this only on older versions.
endif
has('feature')
orhas('*function_name')
. If not, you can still usehas("patch-7.4.123")
to see if what you need is available. I made the plugin helpful.vim which can help you find the version numbers you would want to test.has('nvim-1.2.3')