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 variable.
vim.b[2].foo = 6 -- Set b:foo for buffer 2
<
Note that setting dictionary fields directly will not write them back into
Nvim. This is because the index into the namespace simply returns a copy.
Instead the whole dictionary must be written as one. This can be achieved by
creating a short-lived temporary.
Example: >lua
vim.g.my_dict.field1 = 'value' -- Does not work
local my_dict = vim.g.my_dict --
my_dict.field1 = 'value' -- Instead do
vim.g.my_dict = my_dict --
vim.g *vim.g*
Global (|g:|) editor variables.
Key with no value returns `nil`.
vim.b *vim.b*
Buffer-scoped (|b:|) variables for the current buffer.
Invalid or unset key returns `nil`. Can be indexed with
an integer to access variables for a specific buffer.
vim.w *vim.w*
Window-scoped (|w:|) variables for the current window.
Invalid or unset key returns `nil`. Can be indexed with
an integer to access variables for a specific window.
vim.t *vim.t*
Tabpage-scoped (|t:|) variables for the current tabpage.
Invalid or unset key returns `nil`. Can be indexed with
an integer to access variables for a specific tabpage.
vim.v *vim.v*
|v:| variables.
Invalid or unset key returns `nil`.
*lua-options*
*lua-vim-options*
*lua-vim-set*
*lua-vim-setlocal*
Vim options can be accessed through |vim.o|, which behaves like Vimscript
|:set|.
Examples: ~
To set a boolean toggle:
Vimscript: `set number`
Lua: `vim.o.number = true`
To set a string value:
Vimscript: `set wildignore=*.o,*.a,__pycache__`
Lua: `vim.o.wildignore = '*.o,*.a,__pycache__'`
Similarly, there is |vim.bo| and |vim.wo| for setting buffer-scoped and
window-scoped options. Note that this must NOT be confused with
|local-options| and |:setlocal|. There is also |vim.go| that only accesses the
global value of a |global-local| option, see |:setglobal|.
*vim.opt_local*
*vim.opt_global*
*vim.opt*
A special interface |vim.opt| exists for conveniently interacting with list-
and map-style options from Lua: It allows accessing them as Lua tables and
offers object-oriented method for adding and removing entries.
Examples: ~