nvim_runtime_lua

vim.VersionRange

Methods1

function VersionRange.has(version: string | vim.Version) -> boolean

Check if a version is in the range (inclusive from, exclusive to).

Example:

local r = vim.version.range('1.0.0 - 2.0.0')
print(r:has('1.9.9'))       -- true
print(r:has('2.0.0'))       -- false
print(r:has(vim.version())) -- check against current Nvim version

Or use cmp(), le(), lt(), ge(), gt(), and/or eq() to compare a version against .to and .from directly:

local r = vim.version.range('1.0.0 - 2.0.0') -- >=1.0, <2.0
print(vim.version.ge({1,0,3}, r.from) and vim.version.lt({1,0,3}, r.to))
See:

https://github.com/npm/node-semver#ranges

@since 11

Fields2

VersionRange.from : vim.Version
VersionRange.to : vim.Version | nil