Home Explore Blog CI



neovim

16th chunk of `runtime/doc/lua.txt`
f974127c5db3553c0c661a803a89e49798e85d16eace2d930000000100000fb7
 and at approximately {interval}
    milliseconds (default 200). Nvim still processes other events during this
    time.

    Cannot be called while in an |api-fast| event.

    Examples: >lua
        ---
        -- Wait for 100 ms, allowing other events to process
        vim.wait(100, function() end)

        ---
        -- Wait for 100 ms or until global variable set.
        vim.wait(100, function() return vim.g.waiting_for_var end)

        ---
        -- Wait for 1 second or until global variable set, checking every ~500 ms
        vim.wait(1000, function() return vim.g.waiting_for_var end, 500)

        ---
        -- Schedule a function to set a value in 100ms
        vim.defer_fn(function() vim.g.timer_result = true end, 100)

        -- Would wait ten seconds if results blocked. Actually only waits  100 ms
        if vim.wait(10000, function() return vim.g.timer_result end) then
          print('Only waiting a little bit of time!')
        end
<

    Parameters: ~
      • {time}       (`integer`) Number of milliseconds to wait
      • {callback}   (`fun(): boolean?`) Optional callback. Waits until
                     {callback} returns true
      • {interval}   (`integer?`) (Approximate) number of milliseconds to wait
                     between polls
      • {fast_only}  (`boolean?`) If true, only |api-fast| events will be
                     processed.

    Return (multiple): ~
        (`boolean`)
        (`-1|-2?`)
        • If {callback} returns `true` during the {time}: `true, nil`
        • If {callback} never returns `true` during the {time}: `false, -1`
        • If {callback} is interrupted during the {time}: `false, -2`
        • If {callback} errors, the error is raised.


==============================================================================
LUA-VIMSCRIPT BRIDGE                                           *lua-vimscript*

Nvim Lua provides an interface or "bridge" to Vimscript variables and
functions, and editor commands and options.

Objects passed over this bridge are COPIED (marshalled): there are no
"references". |lua-guide-variables| For example, using `vim.fn.remove()` on a
Lua list copies the list object to Vimscript and does NOT modify the Lua list: >lua
    local list = { 1, 2, 3 }
    vim.fn.remove(list, 0)
    vim.print(list)  --> "{ 1, 2, 3 }"
<


vim.call({func}, {...})                                           *vim.call()*
    Invokes |vim-function| or |user-function| {func} with arguments {...}.
    See also |vim.fn|.
    Equivalent to: >lua
        vim.fn[func]({...})
<
vim.cmd({command})
    See |vim.cmd()|.

vim.fn.{func}({...})                                                  *vim.fn*
    Invokes |vim-function| or |user-function| {func} with arguments {...}.
    To call autoload functions, use the syntax: >lua
        vim.fn['some#function']({...})
<
    Unlike vim.api.|nvim_call_function()| this converts directly between Vim
    objects and Lua objects. If the Vim function returns a float, it will be
    represented directly as a Lua number. Empty lists and dictionaries both
    are represented by an empty table.

    Note: |v:null| values as part of the return value is represented as
    |vim.NIL| special value

    Note: vim.fn keys are generated lazily, thus `pairs(vim.fn)` only
    enumerates functions that were called at least once.

    Note: The majority of functions cannot run in |api-fast| callbacks with some
    undocumented exceptions which are allowed.

                                                           *lua-vim-variables*
The Vim editor global dictionaries |g:| |w:| |b:| |t:| |v:| can be accessed
from Lua conveniently and idiomatically by referencing the `vim.*` Lua tables
described below. In this way you can easily read and modify global Vimscript
variables from Lua.

Example: >lua

    vim.g.foo = 5     -- Set the g:foo Vimscript variable.
    print(vim.g.foo)  -- Get and print the g:foo Vimscript variable.
    vim.g.foo = nil   -- Delete (:unlet) the Vimscript

Title: vim.wait() Details and Lua-Vimscript Bridge
Summary
This section details the `vim.wait()` function, explaining its parameters and return values. It also introduces the Lua-Vimscript bridge in Neovim, which allows interaction with Vimscript variables and functions. Objects are copied during this interaction. The section describes how to call Vimscript functions using `vim.call()` and `vim.fn`, and how to access Vimscript global dictionaries (`g:`, `w:`, `b:`, `t:`, `v:`) through the `vim.*` Lua tables.