Home Explore Blog CI



neovim

52th chunk of `runtime/doc/lua.txt`
762a4e5df64ac73e9a5b84f38c72192c4a6597d0dad9ea800000000100000fc3
 "reasonably close to 1"
    1.x               same
    1.*               same
    1                 same
    *                 any version
    x                 same

    1.2.3 - 2.3.4     is >=1.2.3 <=2.3.4

    Partial right: missing pieces treated as x (2.3 => 2.3.x).
    1.2.3 - 2.3       is >=1.2.3 <2.4.0
    1.2.3 - 2         is >=1.2.3 <3.0.0

    Partial left: missing pieces treated as 0 (1.2 => 1.2.0).
    1.2 - 2.3.0       is 1.2.0 - 2.3.0
<


vim.version.cmp({v1}, {v2})                                *vim.version.cmp()*
    Parses and compares two version objects (the result of
    |vim.version.parse()|, or specified literally as a `{major, minor, patch}`
    tuple, e.g. `{1, 0, 3}`).

    Example: >lua
        if vim.version.cmp({1,0,3}, {0,2,1}) == 0 then
          -- ...
        end
        local v1 = vim.version.parse('1.0.3-pre')
        local v2 = vim.version.parse('0.2.1')
        if vim.version.cmp(v1, v2) == 0 then
          -- ...
        end
<

    Note: ~
      • Per semver, build metadata is ignored when comparing two
        otherwise-equivalent versions.

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {v1}  (`vim.Version|number[]|string`) Version object.
      • {v2}  (`vim.Version|number[]|string`) Version to compare with `v1`.

    Return: ~
        (`integer`) -1 if `v1 < v2`, 0 if `v1 == v2`, 1 if `v1 > v2`.

vim.version.eq({v1}, {v2})                                  *vim.version.eq()*
    Returns `true` if the given versions are equal. See |vim.version.cmp()|
    for usage.

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {v1}  (`vim.Version|number[]|string`)
      • {v2}  (`vim.Version|number[]|string`)

    Return: ~
        (`boolean`)

vim.version.ge({v1}, {v2})                                  *vim.version.ge()*
    Returns `true` if `v1 >= v2`. See |vim.version.cmp()| for usage.

    Attributes: ~
        Since: 0.10.0

    Parameters: ~
      • {v1}  (`vim.Version|number[]|string`)
      • {v2}  (`vim.Version|number[]|string`)

    Return: ~
        (`boolean`)

vim.version.gt({v1}, {v2})                                  *vim.version.gt()*
    Returns `true` if `v1 > v2`. See |vim.version.cmp()| for usage.

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {v1}  (`vim.Version|number[]|string`)
      • {v2}  (`vim.Version|number[]|string`)

    Return: ~
        (`boolean`)

vim.version.last({versions})                              *vim.version.last()*
    TODO: generalize this, move to func.lua

    Parameters: ~
      • {versions}  (`vim.Version[]`)

    Return: ~
        (`vim.Version?`)

vim.version.le({v1}, {v2})                                  *vim.version.le()*
    Returns `true` if `v1 <= v2`. See |vim.version.cmp()| for usage.

    Attributes: ~
        Since: 0.10.0

    Parameters: ~
      • {v1}  (`vim.Version|number[]|string`)
      • {v2}  (`vim.Version|number[]|string`)

    Return: ~
        (`boolean`)

vim.version.lt({v1}, {v2})                                  *vim.version.lt()*
    Returns `true` if `v1 < v2`. See |vim.version.cmp()| for usage.

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {v1}  (`vim.Version|number[]|string`)
      • {v2}  (`vim.Version|number[]|string`)

    Return: ~
        (`boolean`)

vim.version.parse({version}, {opts})                     *vim.version.parse()*
    Parses a semantic version string and returns a version object which can be
    used with other `vim.version` functions. For example "1.0.1-rc1+build.2"
    returns: >
        { major = 1, minor = 0, patch = 1, prerelease = "rc1", build = "build.2" }
<

    Attributes: ~
        Since: 0.9.0

    Parameters: ~
      • {version}  (`string`) Version string to parse.
      • {opts}     (`table?`) Optional keyword arguments:
                   • strict (boolean): Default false. If `true`, no coercion
                     is attempted on input not conforming to semver v2.0.0. If
                     `false`, `parse()`

Title: Lua API: More vim.version Functions
Summary
This section details more functions within the `vim.version` module. It covers `vim.version.cmp()` for comparing version objects, ignoring build metadata. It also provides `vim.version.eq()`, `vim.version.ge()`, `vim.version.gt()`, `vim.version.le()`, and `vim.version.lt()` for equality and inequality comparisons. Additionally, it describes `vim.version.last()` and `vim.version.parse()`, which parses a version string into a version object with properties like major, minor, patch, prerelease, and build, with a strict option to enforce semver v2.0.0 compliance.