2019-11-17 20:06:59 -07:00
|
|
|
|
*lua.txt* Nvim
|
|
|
|
|
|
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
NVIM REFERENCE MANUAL
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Lua engine *lua* *Lua*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Type |gO| to see the table of contents.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
2022-05-11 09:23:46 -07:00
|
|
|
|
INTRODUCTION *lua-intro*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-10-09 05:21:52 -07:00
|
|
|
|
The Lua 5.1 script engine is builtin and always available. Try this command to
|
|
|
|
|
get an idea of what lurks beneath: >
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
:lua print(vim.inspect(package.loaded))
|
2022-10-09 05:21:52 -07:00
|
|
|
|
|
|
|
|
|
Nvim includes a "standard library" |lua-stdlib| for Lua. It complements the
|
|
|
|
|
"editor stdlib" (|builtin-functions| and |Ex-commands|) and the |API|, all of
|
|
|
|
|
which can be used from Lua code (|lua-vimscript| |vim.api|). Together these
|
|
|
|
|
"namespaces" form the Nvim programming interface.
|
|
|
|
|
|
|
|
|
|
The |:source| and |:runtime| commands can run Lua scripts. Lua modules can be
|
|
|
|
|
loaded with `require('name')`, which by convention usually returns a table.
|
|
|
|
|
See |lua-require| for how Nvim finds and loads Lua modules.
|
|
|
|
|
|
|
|
|
|
See this page for more insight into Nvim Lua:
|
|
|
|
|
https://github.com/nanotee/nvim-lua-guide
|
|
|
|
|
|
|
|
|
|
*lua-compat*
|
|
|
|
|
Lua 5.1 is the permanent interface for Nvim Lua. Plugins need only consider
|
|
|
|
|
Lua 5.1, not worry about forward-compatibility with future Lua versions. If
|
|
|
|
|
Nvim ever ships with Lua 5.4+, a Lua 5.1 compatibility shim will be provided
|
|
|
|
|
so that old plugins continue to work transparently.
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
LUA CONCEPTS AND IDIOMS *lua-concepts*
|
|
|
|
|
|
|
|
|
|
Lua is very simple: this means that, while there are some quirks, once you
|
|
|
|
|
internalize those quirks, everything works the same everywhere. Scopes
|
|
|
|
|
(closures) in particular are very consistent, unlike JavaScript or most other
|
|
|
|
|
languages.
|
|
|
|
|
|
|
|
|
|
Lua has three fundamental mechanisms—one for "each major aspect of
|
|
|
|
|
programming": tables, closures, and coroutines.
|
|
|
|
|
https://www.lua.org/doc/cacm2018.pdf
|
|
|
|
|
- Tables are the "object" or container datastructure: they represent both
|
|
|
|
|
lists and maps, you can extend them to represent your own datatypes and
|
|
|
|
|
change their behavior using |luaref-metatable| (like Python's "datamodel").
|
|
|
|
|
- EVERY scope in Lua is a closure: a function is a closure, a module is
|
|
|
|
|
a closure, a `do` block (|luaref-do|) is a closure--and they all work the
|
|
|
|
|
same. A Lua module is literally just a big closure discovered on the "path"
|
|
|
|
|
(where your modules are found: |package.cpath|).
|
|
|
|
|
- Stackful coroutines enable cooperative multithreading, generators, and
|
|
|
|
|
versatile control for both Lua and its host (Nvim).
|
|
|
|
|
|
|
|
|
|
*lua-call-function*
|
|
|
|
|
Lua functions can be called in multiple ways. Consider the function: >
|
|
|
|
|
local foo = function(a, b)
|
|
|
|
|
print("A: ", a)
|
|
|
|
|
print("B: ", b)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
The first way to call this function is: >
|
|
|
|
|
foo(1, 2)
|
|
|
|
|
-- ==== Result ====
|
|
|
|
|
-- A: 1
|
|
|
|
|
-- B: 2
|
|
|
|
|
|
|
|
|
|
This way of calling a function is familiar from most scripting languages.
|
|
|
|
|
In Lua, any missing arguments are passed as `nil`. Example: >
|
|
|
|
|
foo(1)
|
|
|
|
|
-- ==== Result ====
|
|
|
|
|
-- A: 1
|
|
|
|
|
-- B: nil
|
|
|
|
|
|
|
|
|
|
Furthermore it is not an error if extra parameters are passed, they are just
|
|
|
|
|
discarded.
|
|
|
|
|
|
|
|
|
|
It is also allowed to omit the parentheses (only) if the function takes
|
|
|
|
|
exactly one string (`"foo"`) or table literal (`{1,2,3}`). The latter is often
|
|
|
|
|
used to approximate the "named parameters" feature of languages like Python
|
|
|
|
|
("kwargs" or "keyword args"). Example: >
|
|
|
|
|
local func_with_opts = function(opts)
|
|
|
|
|
local will_do_foo = opts.foo
|
|
|
|
|
local filename = opts.filename
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
func_with_opts { foo = true, filename = "hello.world" }
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2022-10-09 05:21:52 -07:00
|
|
|
|
There is nothing special going on here except that parentheses are treated as
|
|
|
|
|
whitespace. But visually, this small bit of sugar gets reasonably close to
|
|
|
|
|
a "keyword args" interface.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-10-09 05:21:52 -07:00
|
|
|
|
It is of course also valid to call the function with parentheses: >
|
2021-08-26 02:39:29 -07:00
|
|
|
|
|
2022-10-09 05:21:52 -07:00
|
|
|
|
func_with_opts({ foo = true, filename = "hello.world" })
|
|
|
|
|
<
|
|
|
|
|
Nvim tends to prefer the keyword args style.
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
LUA PATTERNS *lua-patterns*
|
|
|
|
|
|
|
|
|
|
Lua intentionally does not support regular expressions, instead it has limited
|
|
|
|
|
"patterns" which avoid the performance pitfalls of extended regex.
|
|
|
|
|
|luaref-patterns|
|
|
|
|
|
|
|
|
|
|
Examples using |string.match()|: >
|
|
|
|
|
|
|
|
|
|
print(string.match("foo123bar123", "%d+"))
|
|
|
|
|
-- 123
|
|
|
|
|
|
|
|
|
|
print(string.match("foo123bar123", "[^%d]+"))
|
|
|
|
|
-- foo
|
|
|
|
|
|
|
|
|
|
print(string.match("foo123bar123", "[abc]+"))
|
|
|
|
|
-- ba
|
|
|
|
|
|
|
|
|
|
print(string.match("foo.bar", "%.bar"))
|
|
|
|
|
-- .bar
|
|
|
|
|
|
|
|
|
|
For more complex matching you can use Vim regex from Lua via |vim.regex()|.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
2022-05-11 09:23:46 -07:00
|
|
|
|
IMPORTING LUA MODULES *lua-require*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2021-08-26 02:39:29 -07:00
|
|
|
|
Modules are searched for under the directories specified in 'runtimepath', in
|
2022-10-09 05:21:52 -07:00
|
|
|
|
the order they appear. Any "." in the module name is treated as a directory
|
|
|
|
|
separator when searching. For a module `foo.bar`, each directory is searched
|
|
|
|
|
for `lua/foo/bar.lua`, then `lua/foo/bar/init.lua`. If no files are found,
|
2021-11-21 04:11:32 -07:00
|
|
|
|
the directories are searched again for a shared library with a name matching
|
2022-05-11 09:23:46 -07:00
|
|
|
|
`lua/foo/bar.?`, where `?` is a list of suffixes (such as `so` or `dll`) derived from
|
2022-08-08 09:58:32 -07:00
|
|
|
|
the initial value of |package.cpath|. If still no files are found, Nvim falls
|
2022-05-11 09:23:46 -07:00
|
|
|
|
back to Lua's default search mechanism. The first script found is run and
|
|
|
|
|
`require()` returns the value returned by the script if any, else `true`.
|
|
|
|
|
|
|
|
|
|
The return value is cached after the first call to `require()` for each module,
|
|
|
|
|
with subsequent calls returning the cached value without searching for, or
|
|
|
|
|
executing any script. For further details on `require()`, see the Lua
|
2021-08-26 02:39:29 -07:00
|
|
|
|
documentation at https://www.lua.org/manual/5.1/manual.html#pdf-require.
|
|
|
|
|
|
2022-08-08 09:58:32 -07:00
|
|
|
|
For example, if 'runtimepath' is `foo,bar` and |package.cpath| was
|
2021-11-21 04:11:32 -07:00
|
|
|
|
`./?.so;./?.dll` at startup, `require('mod')` searches these paths in order
|
2022-10-09 09:19:43 -07:00
|
|
|
|
and loads the first module found ("first wins"): >
|
2021-08-26 02:39:29 -07:00
|
|
|
|
foo/lua/mod.lua
|
|
|
|
|
foo/lua/mod/init.lua
|
2021-11-21 04:11:32 -07:00
|
|
|
|
bar/lua/mod.lua
|
2021-08-26 02:39:29 -07:00
|
|
|
|
bar/lua/mod/init.lua
|
2021-11-21 04:11:32 -07:00
|
|
|
|
foo/lua/mod.so
|
|
|
|
|
foo/lua/mod.dll
|
|
|
|
|
bar/lua/mod.so
|
|
|
|
|
bar/lua/mod.dll
|
2022-10-09 09:19:43 -07:00
|
|
|
|
<
|
2022-10-09 05:21:52 -07:00
|
|
|
|
*lua-package-path*
|
2022-08-08 09:58:32 -07:00
|
|
|
|
Nvim automatically adjusts |package.path| and |package.cpath| according to the
|
2022-05-11 09:23:46 -07:00
|
|
|
|
effective 'runtimepath' value. Adjustment happens whenever 'runtimepath' is
|
2022-10-09 05:21:52 -07:00
|
|
|
|
changed. `package.path` is adjusted by simply appending `/lua/?.lua` and
|
2019-11-17 20:06:59 -07:00
|
|
|
|
`/lua/?/init.lua` to each directory from 'runtimepath' (`/` is actually the
|
|
|
|
|
first character of `package.config`).
|
|
|
|
|
|
2022-08-08 09:58:32 -07:00
|
|
|
|
Similarly to |package.path|, modified directories from 'runtimepath' are also
|
|
|
|
|
added to |package.cpath|. In this case, instead of appending `/lua/?.lua` and
|
2019-11-17 20:06:59 -07:00
|
|
|
|
`/lua/?/init.lua` to each runtimepath, all unique `?`-containing suffixes of
|
2022-08-08 09:58:32 -07:00
|
|
|
|
the existing |package.cpath| are used. Example:
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-10-09 09:19:43 -07:00
|
|
|
|
- 1. Given that
|
2019-11-17 20:06:59 -07:00
|
|
|
|
- 'runtimepath' contains `/foo/bar,/xxx;yyy/baz,/abc`;
|
2022-10-09 09:19:43 -07:00
|
|
|
|
- initial |package.cpath| (defined at compile-time or derived from
|
|
|
|
|
`$LUA_CPATH` / `$LUA_INIT`) contains `./?.so;/def/ghi/a?d/j/g.elf;/def/?.so`.
|
|
|
|
|
- 2. It finds `?`-containing suffixes `/?.so`, `/a?d/j/g.elf` and `/?.so`, in
|
|
|
|
|
order: parts of the path starting from the first path component containing
|
|
|
|
|
question mark and preceding path separator.
|
|
|
|
|
- 3. The suffix of `/def/?.so`, namely `/?.so` is not unique, as it’s the same
|
|
|
|
|
as the suffix of the first path from |package.path| (i.e. `./?.so`). Which
|
|
|
|
|
leaves `/?.so` and `/a?d/j/g.elf`, in this order.
|
|
|
|
|
- 4. 'runtimepath' has three paths: `/foo/bar`, `/xxx;yyy/baz` and `/abc`. The
|
|
|
|
|
second one contains a semicolon which is a paths separator so it is out,
|
|
|
|
|
leaving only `/foo/bar` and `/abc`, in order.
|
|
|
|
|
- 5. The cartesian product of paths from 4. and suffixes from 3. is taken,
|
|
|
|
|
giving four variants. In each variant a `/lua` path segment is inserted
|
|
|
|
|
between path and suffix, leaving:
|
|
|
|
|
- `/foo/bar/lua/?.so`
|
|
|
|
|
- `/foo/bar/lua/a?d/j/g.elf`
|
|
|
|
|
- `/abc/lua/?.so`
|
|
|
|
|
- `/abc/lua/a?d/j/g.elf`
|
|
|
|
|
- 6. New paths are prepended to the original |package.cpath|.
|
|
|
|
|
|
|
|
|
|
The result will look like this: >
|
|
|
|
|
|
|
|
|
|
/foo/bar,/xxx;yyy/baz,/abc ('runtimepath')
|
|
|
|
|
× ./?.so;/def/ghi/a?d/j/g.elf;/def/?.so (package.cpath)
|
|
|
|
|
= /foo/bar/lua/?.so;/foo/bar/lua/a?d/j/g.elf;/abc/lua/?.so;/abc/lua/a?d/j/g.elf;./?.so;/def/ghi/a?d/j/g.elf;/def/?.so
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
|
|
|
|
|
- To track 'runtimepath' updates, paths added at previous update are
|
|
|
|
|
remembered and removed at the next update, while all paths derived from the
|
2022-05-11 09:23:46 -07:00
|
|
|
|
new 'runtimepath' are prepended as described above. This allows removing
|
2019-11-17 20:06:59 -07:00
|
|
|
|
paths when path is removed from 'runtimepath', adding paths when they are
|
2022-08-08 09:58:32 -07:00
|
|
|
|
added and reordering |package.path|/|package.cpath| content if 'runtimepath'
|
2019-11-17 20:06:59 -07:00
|
|
|
|
was reordered.
|
|
|
|
|
|
|
|
|
|
- Although adjustments happen automatically, Nvim does not track current
|
2022-08-08 09:58:32 -07:00
|
|
|
|
values of |package.path| or |package.cpath|. If you happen to delete some
|
2019-11-17 20:06:59 -07:00
|
|
|
|
paths from there you can set 'runtimepath' to trigger an update: >
|
|
|
|
|
let &runtimepath = &runtimepath
|
|
|
|
|
|
|
|
|
|
- Skipping paths from 'runtimepath' which contain semicolons applies both to
|
2022-08-08 09:58:32 -07:00
|
|
|
|
|package.path| and |package.cpath|. Given that there are some badly written
|
2022-05-11 09:23:46 -07:00
|
|
|
|
plugins using shell, which will not work with paths containing semicolons,
|
|
|
|
|
it is better to not have them in 'runtimepath' at all.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
2022-05-11 09:23:46 -07:00
|
|
|
|
COMMANDS *lua-commands*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
These commands execute a Lua chunk from either the command line (:lua, :luado)
|
|
|
|
|
or a file (:luafile) on the given line [range]. As always in Lua, each chunk
|
|
|
|
|
has its own scope (closure), so only global variables are shared between
|
|
|
|
|
command calls. The |lua-stdlib| modules, user modules, and anything else on
|
2022-09-25 16:58:27 -07:00
|
|
|
|
|package.path| are available.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
The Lua print() function redirects its output to the Nvim message area, with
|
|
|
|
|
arguments separated by " " (space) instead of "\t" (tab).
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*:lua*
|
2022-06-14 17:49:54 -07:00
|
|
|
|
:lua {chunk}
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Executes Lua chunk {chunk}. If {chunk} starts with "=" the rest of the
|
2022-01-03 22:05:15 -07:00
|
|
|
|
chunk is evaluated as an expression and printed. `:lua =expr` is
|
|
|
|
|
equivalent to `:lua print(vim.inspect(expr))`
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Examples: >
|
|
|
|
|
:lua vim.api.nvim_command('echo "Hello, Nvim!"')
|
|
|
|
|
< To see the Lua version: >
|
|
|
|
|
:lua print(_VERSION)
|
|
|
|
|
< To see the LuaJIT version: >
|
2022-01-03 22:05:15 -07:00
|
|
|
|
:lua =jit.version
|
2019-11-17 20:06:59 -07:00
|
|
|
|
<
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*:lua-heredoc*
|
2022-06-14 17:49:54 -07:00
|
|
|
|
:lua << [endmarker]
|
2019-11-17 20:06:59 -07:00
|
|
|
|
{script}
|
|
|
|
|
{endmarker}
|
|
|
|
|
Executes Lua script {script} from within Vimscript. {endmarker} must NOT
|
|
|
|
|
be preceded by whitespace. You can omit [endmarker] after the "<<" and use
|
|
|
|
|
a dot "." after {script} (similar to |:append|, |:insert|).
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Example: >
|
|
|
|
|
function! CurrentLineInfo()
|
|
|
|
|
lua << EOF
|
|
|
|
|
local linenr = vim.api.nvim_win_get_cursor(0)[1]
|
|
|
|
|
local curline = vim.api.nvim_buf_get_lines(
|
|
|
|
|
0, linenr - 1, linenr, false)[1]
|
|
|
|
|
print(string.format("Current line [%d] has %d bytes",
|
|
|
|
|
linenr, #curline))
|
|
|
|
|
EOF
|
|
|
|
|
endfunction
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
|
|
|
|
Note that the `local` variables will disappear when the block finishes.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
But not globals.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*:luado*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
:[range]luado {body}
|
|
|
|
|
Executes Lua chunk "function(line, linenr) {body} end" for each buffer
|
|
|
|
|
line in [range], where `line` is the current line text (without <EOL>),
|
|
|
|
|
and `linenr` is the current line number. If the function returns a string
|
|
|
|
|
that becomes the text of the corresponding buffer line. Default [range] is
|
|
|
|
|
the whole file: "1,$".
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Examples: >
|
|
|
|
|
:luado return string.format("%s\t%d", line:reverse(), #line)
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
:lua require"lpeg"
|
|
|
|
|
:lua -- balanced parenthesis grammar:
|
|
|
|
|
:lua bp = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" }
|
2022-10-09 09:19:43 -07:00
|
|
|
|
:luado if bp:match(line) then return "=>\t" .. line end
|
2019-11-17 20:06:59 -07:00
|
|
|
|
<
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*:luafile*
|
2022-06-14 17:49:54 -07:00
|
|
|
|
:luafile {file}
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Execute Lua script in {file}.
|
|
|
|
|
The whole argument is used as the filename (like |:edit|), spaces do not
|
|
|
|
|
need to be escaped. Alternatively you can |:source| Lua files.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Examples: >
|
2019-11-17 20:06:59 -07:00
|
|
|
|
:luafile script.lua
|
|
|
|
|
:luafile %
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
==============================================================================
|
2022-05-11 09:23:46 -07:00
|
|
|
|
luaeval() *lua-eval* *luaeval()*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
The (dual) equivalent of "vim.eval" for passing Lua values to Nvim is
|
2022-05-11 09:23:46 -07:00
|
|
|
|
"luaeval". "luaeval" takes an expression string and an optional argument used
|
|
|
|
|
for _A inside expression and returns the result of the expression. It is
|
|
|
|
|
semantically equivalent in Lua to: >
|
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
local chunkheader = "local _A = select(1, ...) return "
|
|
|
|
|
function luaeval (expstr, arg)
|
|
|
|
|
local chunk = assert(loadstring(chunkheader .. expstr, "luaeval"))
|
|
|
|
|
return chunk(arg) -- return typval
|
|
|
|
|
end
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Lua nils, numbers, strings, tables and booleans are converted to their
|
2021-07-31 13:45:58 -07:00
|
|
|
|
respective Vimscript types. If a Lua string contains a NUL byte, it will be
|
|
|
|
|
converted to a |Blob|. Conversion of other Lua types is an error.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
The magic global "_A" contains the second argument to luaeval().
|
|
|
|
|
|
|
|
|
|
Example: >
|
|
|
|
|
:echo luaeval('_A[1] + _A[2]', [40, 2])
|
|
|
|
|
42
|
|
|
|
|
:echo luaeval('string.match(_A, "[a-z]+")', 'XYXfoo123')
|
|
|
|
|
foo
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Lua tables are used as both dictionaries and lists, so it is impossible to
|
|
|
|
|
determine whether empty table is meant to be empty list or empty dictionary.
|
|
|
|
|
Additionally Lua does not have integer numbers. To distinguish between these
|
|
|
|
|
cases there is the following agreement:
|
|
|
|
|
|
|
|
|
|
0. Empty table is empty list.
|
2022-05-11 09:23:46 -07:00
|
|
|
|
1. Table with N incrementally growing integral numbers, starting from 1 and
|
2019-11-17 20:06:59 -07:00
|
|
|
|
ending with N is considered to be a list.
|
2022-05-11 09:23:46 -07:00
|
|
|
|
2. Table with string keys, none of which contains NUL byte, is considered to
|
2019-11-17 20:06:59 -07:00
|
|
|
|
be a dictionary.
|
2022-05-11 09:23:46 -07:00
|
|
|
|
3. Table with string keys, at least one of which contains NUL byte, is also
|
|
|
|
|
considered to be a dictionary, but this time it is converted to
|
2019-11-17 20:06:59 -07:00
|
|
|
|
a |msgpack-special-map|.
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*lua-special-tbl*
|
|
|
|
|
4. Table with `vim.type_idx` key may be a dictionary, a list or floating-point
|
2019-11-17 20:06:59 -07:00
|
|
|
|
value:
|
2021-09-14 10:20:33 -07:00
|
|
|
|
- `{[vim.type_idx]=vim.types.float, [vim.val_idx]=1}` is converted to
|
|
|
|
|
a floating-point 1.0. Note that by default integral Lua numbers are
|
|
|
|
|
converted to |Number|s, non-integral are converted to |Float|s. This
|
2019-11-17 20:06:59 -07:00
|
|
|
|
variant allows integral |Float|s.
|
2021-09-14 10:20:33 -07:00
|
|
|
|
- `{[vim.type_idx]=vim.types.dictionary}` is converted to an empty
|
|
|
|
|
dictionary, `{[vim.type_idx]=vim.types.dictionary, [42]=1, a=2}` is
|
|
|
|
|
converted to a dictionary `{'a': 42}`: non-string keys are ignored.
|
|
|
|
|
Without `vim.type_idx` key tables with keys not fitting in 1., 2. or 3.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
are errors.
|
2021-09-14 10:20:33 -07:00
|
|
|
|
- `{[vim.type_idx]=vim.types.array}` is converted to an empty list. As well
|
|
|
|
|
as `{[vim.type_idx]=vim.types.array, [42]=1}`: integral keys that do not
|
|
|
|
|
form a 1-step sequence from 1 to N are ignored, as well as all
|
2019-11-17 20:06:59 -07:00
|
|
|
|
non-integral keys.
|
|
|
|
|
|
|
|
|
|
Examples: >
|
|
|
|
|
|
|
|
|
|
:echo luaeval('math.pi')
|
|
|
|
|
:function Rand(x,y) " random uniform between x and y
|
|
|
|
|
: return luaeval('(_A.y-_A.x)*math.random()+_A.x', {'x':a:x,'y':a:y})
|
|
|
|
|
: endfunction
|
|
|
|
|
:echo Rand(1,10)
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
|
|
|
|
Note: Second argument to `luaeval` is converted ("marshalled") from Vimscript
|
2021-09-14 10:20:33 -07:00
|
|
|
|
to Lua, so changes to Lua containers do not affect values in Vimscript. Return
|
|
|
|
|
value is also always converted. When converting, |msgpack-special-dict|s are
|
|
|
|
|
treated specially.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Vimscript v:lua interface *v:lua-call*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
From Vimscript the special `v:lua` prefix can be used to call Lua functions
|
|
|
|
|
which are global or accessible from global tables. The expression >
|
|
|
|
|
v:lua.func(arg1, arg2)
|
|
|
|
|
is equivalent to the Lua chunk >
|
|
|
|
|
return func(...)
|
|
|
|
|
where the args are converted to Lua values. The expression >
|
|
|
|
|
v:lua.somemod.func(args)
|
|
|
|
|
is equivalent to the Lua chunk >
|
|
|
|
|
return somemod.func(...)
|
|
|
|
|
|
2021-10-23 09:20:19 -07:00
|
|
|
|
In addition, functions of packages can be accessed like >
|
|
|
|
|
v:lua.require'mypack'.func(arg1, arg2)
|
|
|
|
|
v:lua.require'mypack.submod'.func(arg1, arg2)
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Note: Only single quote form without parens is allowed. Using
|
2021-10-23 09:20:19 -07:00
|
|
|
|
`require"mypack"` or `require('mypack')` as prefixes do NOT work (the latter
|
|
|
|
|
is still valid as a function call of itself, in case require returns a useful
|
|
|
|
|
value).
|
|
|
|
|
|
2021-08-11 05:47:33 -07:00
|
|
|
|
The `v:lua` prefix may be used to call Lua functions as |method|s. For
|
|
|
|
|
example: >
|
|
|
|
|
arg1->v:lua.somemod.func(arg2)
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2019-11-17 20:06:59 -07:00
|
|
|
|
You can use `v:lua` in "func" options like 'tagfunc', 'omnifunc', etc.
|
|
|
|
|
For example consider the following Lua omnifunc handler: >
|
|
|
|
|
|
|
|
|
|
function mymod.omnifunc(findstart, base)
|
|
|
|
|
if findstart == 1 then
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
return {'stuff', 'steam', 'strange things'}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
vim.api.nvim_buf_set_option(0, 'omnifunc', 'v:lua.mymod.omnifunc')
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Note: The module ("mymod" in the above example) must either be a Lua global,
|
2021-10-23 09:20:19 -07:00
|
|
|
|
or use the require syntax as specified above to access it from a package.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Note: `v:lua` without a call is not allowed in a Vimscript expression:
|
|
|
|
|
|Funcref|s cannot represent Lua functions. The following are errors: >
|
|
|
|
|
|
|
|
|
|
let g:Myvar = v:lua.myfunc " Error
|
|
|
|
|
call SomeFunc(v:lua.mycallback) " Error
|
|
|
|
|
let g:foo = v:lua " Error
|
|
|
|
|
let g:foo = v:['lua'] " Error
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2019-11-17 20:06:59 -07:00
|
|
|
|
==============================================================================
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Lua standard modules *lua-stdlib*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
The Nvim Lua "standard library" (stdlib) is the `vim` module, which exposes
|
2022-05-11 09:23:46 -07:00
|
|
|
|
various functions and sub-modules. It is always loaded, thus `require("vim")`
|
2019-11-17 20:06:59 -07:00
|
|
|
|
is unnecessary.
|
|
|
|
|
|
|
|
|
|
You can peek at the module properties: >
|
|
|
|
|
|
|
|
|
|
:lua print(vim.inspect(vim))
|
|
|
|
|
|
|
|
|
|
Result is something like this: >
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
_os_proc_children = <function 1>,
|
|
|
|
|
_os_proc_info = <function 2>,
|
|
|
|
|
...
|
|
|
|
|
api = {
|
|
|
|
|
nvim__id = <function 5>,
|
|
|
|
|
nvim__id_array = <function 6>,
|
|
|
|
|
...
|
|
|
|
|
},
|
|
|
|
|
deepcopy = <function 106>,
|
|
|
|
|
gsplit = <function 107>,
|
|
|
|
|
...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
To find documentation on e.g. the "deepcopy" function: >
|
|
|
|
|
|
|
|
|
|
:help vim.deepcopy()
|
|
|
|
|
|
|
|
|
|
Note that underscore-prefixed functions (e.g. "_os_proc_children") are
|
|
|
|
|
internal/private and must not be used by plugins.
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
2022-05-11 09:23:46 -07:00
|
|
|
|
VIM.LOOP *lua-loop* *vim.loop*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
`vim.loop` exposes all features of the Nvim event-loop. This is a low-level
|
2019-11-17 20:06:59 -07:00
|
|
|
|
API that provides functionality for networking, filesystem, and process
|
2022-05-11 09:23:46 -07:00
|
|
|
|
management. Try this command to see available functions: >
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
:lua print(vim.inspect(vim.loop))
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2022-08-09 04:21:50 -07:00
|
|
|
|
Internally, `vim.loop` wraps the "luv" Lua bindings for the LibUV library;
|
|
|
|
|
see |luv-intro| for a full reference manual.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*E5560* *lua-loop-callbacks*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
It is an error to directly invoke `vim.api` functions (except |api-fast|) in
|
2022-05-11 09:23:46 -07:00
|
|
|
|
`vim.loop` callbacks. For example, this is an error: >
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
local timer = vim.loop.new_timer()
|
|
|
|
|
timer:start(1000, 0, function()
|
|
|
|
|
vim.api.nvim_command('echomsg "test"')
|
|
|
|
|
end)
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2019-11-17 20:06:59 -07:00
|
|
|
|
To avoid the error use |vim.schedule_wrap()| to defer the callback: >
|
|
|
|
|
|
|
|
|
|
local timer = vim.loop.new_timer()
|
|
|
|
|
timer:start(1000, 0, vim.schedule_wrap(function()
|
|
|
|
|
vim.api.nvim_command('echomsg "test"')
|
|
|
|
|
end))
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
|
|
|
|
(For one-shot timers, see |vim.defer_fn()|, which automatically adds the
|
|
|
|
|
wrapping.)
|
2020-07-07 01:55:40 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Example: repeating timer
|
|
|
|
|
1. Save this code to a file.
|
|
|
|
|
2. Execute it with ":luafile %". >
|
|
|
|
|
|
|
|
|
|
-- Create a timer handle (implementation detail: uv_timer_t).
|
|
|
|
|
local timer = vim.loop.new_timer()
|
|
|
|
|
local i = 0
|
|
|
|
|
-- Waits 1000ms, then repeats every 750ms until timer:close().
|
|
|
|
|
timer:start(1000, 750, function()
|
|
|
|
|
print('timer invoked! i='..tostring(i))
|
|
|
|
|
if i > 4 then
|
|
|
|
|
timer:close() -- Always close handles to avoid leaks.
|
|
|
|
|
end
|
|
|
|
|
i = i + 1
|
|
|
|
|
end)
|
|
|
|
|
print('sleeping');
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
|
|
|
|
Example: File-change detection *watch-file*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
1. Save this code to a file.
|
|
|
|
|
2. Execute it with ":luafile %".
|
|
|
|
|
3. Use ":Watch %" to watch any file.
|
|
|
|
|
4. Try editing the file from another text editor.
|
|
|
|
|
5. Observe that the file reloads in Nvim (because on_change() calls
|
|
|
|
|
|:checktime|). >
|
|
|
|
|
|
|
|
|
|
local w = vim.loop.new_fs_event()
|
|
|
|
|
local function on_change(err, fname, status)
|
|
|
|
|
-- Do work...
|
|
|
|
|
vim.api.nvim_command('checktime')
|
|
|
|
|
-- Debounce: stop/start.
|
|
|
|
|
w:stop()
|
|
|
|
|
watch_file(fname)
|
|
|
|
|
end
|
|
|
|
|
function watch_file(fname)
|
|
|
|
|
local fullpath = vim.api.nvim_call_function(
|
|
|
|
|
'fnamemodify', {fname, ':p'})
|
|
|
|
|
w:start(fullpath, {}, vim.schedule_wrap(function(...)
|
|
|
|
|
on_change(...) end))
|
|
|
|
|
end
|
|
|
|
|
vim.api.nvim_command(
|
|
|
|
|
"command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
|
|
|
|
Example: TCP echo-server *tcp-server*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
1. Save this code to a file.
|
|
|
|
|
2. Execute it with ":luafile %".
|
|
|
|
|
3. Note the port number.
|
|
|
|
|
4. Connect from any TCP client (e.g. "nc 0.0.0.0 36795"): >
|
|
|
|
|
|
|
|
|
|
local function create_server(host, port, on_connect)
|
|
|
|
|
local server = vim.loop.new_tcp()
|
|
|
|
|
server:bind(host, port)
|
|
|
|
|
server:listen(128, function(err)
|
|
|
|
|
assert(not err, err) -- Check for errors.
|
|
|
|
|
local sock = vim.loop.new_tcp()
|
|
|
|
|
server:accept(sock) -- Accept client connection.
|
|
|
|
|
on_connect(sock) -- Start reading messages.
|
|
|
|
|
end)
|
|
|
|
|
return server
|
|
|
|
|
end
|
|
|
|
|
local server = create_server('0.0.0.0', 0, function(sock)
|
|
|
|
|
sock:read_start(function(err, chunk)
|
|
|
|
|
assert(not err, err) -- Check for errors.
|
|
|
|
|
if chunk then
|
|
|
|
|
sock:write(chunk) -- Echo received messages to the channel.
|
|
|
|
|
else -- EOF (stream closed).
|
|
|
|
|
sock:close() -- Always close handles to avoid leaks.
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
print('TCP echo-server listening on port: '..server:getsockname().port)
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
|
|
|
|
Multithreading *lua-loop-threading*
|
2022-02-26 03:03:39 -07:00
|
|
|
|
|
|
|
|
|
Plugins can perform work in separate (os-level) threads using the threading
|
|
|
|
|
APIs in luv, for instance `vim.loop.new_thread`. Note that every thread
|
|
|
|
|
gets its own separate lua interpreter state, with no access to lua globals
|
|
|
|
|
in the main thread. Neither can the state of the editor (buffers, windows,
|
|
|
|
|
etc) be directly accessed from threads.
|
|
|
|
|
|
|
|
|
|
A subset of the `vim.*` API is available in threads. This includes:
|
|
|
|
|
|
|
|
|
|
- `vim.loop` with a separate event loop per thread.
|
|
|
|
|
- `vim.mpack` and `vim.json` (useful for serializing messages between threads)
|
2022-09-25 16:58:27 -07:00
|
|
|
|
- `require` in threads can use lua packages from the global |package.path|
|
2022-02-26 03:03:39 -07:00
|
|
|
|
- `print()` and `vim.inspect`
|
|
|
|
|
- `vim.diff`
|
|
|
|
|
- most utility functions in `vim.*` for working with pure lua values
|
|
|
|
|
like `vim.split`, `vim.tbl_*`, `vim.list_*`, and so on.
|
|
|
|
|
- `vim.is_thread()` returns true from a non-main thread.
|
|
|
|
|
|
2020-05-18 06:49:50 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
2022-05-11 09:23:46 -07:00
|
|
|
|
VIM.HIGHLIGHT *lua-highlight*
|
2020-05-18 06:49:50 -07:00
|
|
|
|
|
|
|
|
|
Nvim includes a function for highlighting a selection on yank (see for example
|
|
|
|
|
https://github.com/machakann/vim-highlightedyank). To enable it, add
|
|
|
|
|
>
|
2020-07-05 18:30:12 -07:00
|
|
|
|
au TextYankPost * silent! lua vim.highlight.on_yank()
|
2020-05-18 06:49:50 -07:00
|
|
|
|
<
|
|
|
|
|
to your `init.vim`. You can customize the highlight group and the duration of
|
|
|
|
|
the highlight via
|
|
|
|
|
>
|
2020-07-05 18:30:12 -07:00
|
|
|
|
au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=150}
|
2020-05-18 06:49:50 -07:00
|
|
|
|
<
|
2020-06-03 07:51:25 -07:00
|
|
|
|
If you want to exclude visual selections from highlighting on yank, use
|
|
|
|
|
>
|
2020-07-05 18:30:12 -07:00
|
|
|
|
au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}
|
2020-06-03 07:51:25 -07:00
|
|
|
|
<
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.highlight.on_yank({opts}) *vim.highlight.on_yank()*
|
2020-07-05 18:30:12 -07:00
|
|
|
|
Highlights the yanked text. The fields of the optional dict {opts}
|
|
|
|
|
control the highlight:
|
2021-08-27 03:59:13 -07:00
|
|
|
|
- {higroup} highlight group for yanked region (default |hl-IncSearch|)
|
2020-07-05 18:30:12 -07:00
|
|
|
|
- {timeout} time in ms before highlight is cleared (default `150`)
|
|
|
|
|
- {on_macro} highlight when executing macro (default `false`)
|
|
|
|
|
- {on_visual} highlight when yanking visual selection (default `true`)
|
2021-08-27 03:59:13 -07:00
|
|
|
|
- {event} event structure (default |v:event|)
|
2020-05-31 11:56:00 -07:00
|
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
|
vim.highlight.range({bufnr}, {ns}, {hlgroup}, {start}, {finish}, {opts})
|
2020-05-31 11:56:00 -07:00
|
|
|
|
*vim.highlight.range()*
|
2022-02-21 13:21:42 -07:00
|
|
|
|
|
|
|
|
|
Apply highlight group to range of text.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
|
Parameters: ~
|
2022-10-09 09:19:43 -07:00
|
|
|
|
• {bufnr} buffer number
|
|
|
|
|
• {ns} namespace for highlights
|
|
|
|
|
• {hlgroup} highlight group name
|
|
|
|
|
• {start} starting position (tuple {line,col})
|
|
|
|
|
• {finish} finish position (tuple {line,col})
|
|
|
|
|
• {opts} optional parameters:
|
2022-02-21 13:21:42 -07:00
|
|
|
|
• `regtype`: type of range (characterwise, linewise,
|
2022-09-25 16:58:27 -07:00
|
|
|
|
or blockwise, see |setreg()|), default `'v'`
|
2022-05-11 09:23:46 -07:00
|
|
|
|
• `inclusive`: range includes end position,
|
|
|
|
|
default `false`
|
2022-02-21 13:21:42 -07:00
|
|
|
|
• `priority`: priority of highlight, default
|
|
|
|
|
`vim.highlight.user` (see below)
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.highlight.priorities *vim.highlight.priorities*
|
2022-02-21 13:21:42 -07:00
|
|
|
|
|
|
|
|
|
Table with default priorities used for highlighting:
|
|
|
|
|
• `syntax`: `50`, used for standard syntax highlighting
|
|
|
|
|
• `treesitter`: `100`, used for tree-sitter-based highlighting
|
|
|
|
|
• `diagnostics`: `150`, used for code analysis such as diagnostics
|
|
|
|
|
• `user`: `200`, used for user-triggered highlights such as LSP document
|
|
|
|
|
symbols or `on_yank` autocommands
|
2020-05-31 11:56:00 -07:00
|
|
|
|
|
2019-11-04 12:40:30 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
2022-05-11 09:23:46 -07:00
|
|
|
|
VIM.REGEX *lua-regex*
|
2019-11-04 12:40:30 -07:00
|
|
|
|
|
|
|
|
|
Vim regexes can be used directly from lua. Currently they only allow
|
|
|
|
|
matching within a single line.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.regex({re}) *vim.regex()*
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Parse the Vim regex {re} and return a regex object. Regexes are "magic"
|
2022-05-16 12:30:00 -07:00
|
|
|
|
and case-sensitive by default, regardless of 'magic' and 'ignorecase'.
|
|
|
|
|
They can be controlled with flags, see |/magic| and |/ignorecase|.
|
2019-11-04 12:40:30 -07:00
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Methods on the regex object:
|
2019-11-04 12:40:30 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
regex:match_str({str}) *regex:match_str()*
|
2019-11-04 12:40:30 -07:00
|
|
|
|
Match the string against the regex. If the string should match the regex
|
|
|
|
|
precisely, surround the regex with `^` and `$`. If the was a match, the
|
|
|
|
|
byte indices for the beginning and end of the match is returned. When
|
|
|
|
|
there is no match, `nil` is returned. As any integer is truth-y,
|
|
|
|
|
`regex:match()` can be directly used as a condition in an if-statement.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
regex:match_line({bufnr}, {line_idx} [, {start}, {end}]) *regex:match_line()*
|
2019-11-04 12:40:30 -07:00
|
|
|
|
Match line {line_idx} (zero-based) in buffer {bufnr}. If {start} and {end}
|
|
|
|
|
are supplied, match only this byte index range. Otherwise see
|
|
|
|
|
|regex:match_str()|. If {start} is used, then the returned byte indices
|
|
|
|
|
will be relative {start}.
|
|
|
|
|
|
2021-08-22 04:52:56 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
VIM.DIFF *lua-diff*
|
|
|
|
|
|
|
|
|
|
vim.diff({a}, {b}, {opts}) *vim.diff()*
|
|
|
|
|
Run diff on strings {a} and {b}. Any indices returned by this function,
|
|
|
|
|
either directly or via callback arguments, are 1-based.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2021-08-22 04:52:56 -07:00
|
|
|
|
Examples: >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.diff('a\n', 'b\nc\n')
|
2022-10-09 09:19:43 -07:00
|
|
|
|
=>
|
2022-05-11 09:23:46 -07:00
|
|
|
|
@@ -1 +1,2 @@
|
|
|
|
|
-a
|
|
|
|
|
+b
|
|
|
|
|
+c
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.diff('a\n', 'b\nc\n', {result_type = 'indices'})
|
2022-10-09 09:19:43 -07:00
|
|
|
|
=>
|
2022-05-11 09:23:46 -07:00
|
|
|
|
{
|
|
|
|
|
{1, 1, 1, 2}
|
|
|
|
|
}
|
2021-08-22 04:52:56 -07:00
|
|
|
|
<
|
|
|
|
|
Parameters: ~
|
2022-10-09 09:19:43 -07:00
|
|
|
|
• {a} First string to compare
|
|
|
|
|
• {b} Second string to compare
|
|
|
|
|
• {opts} Optional parameters:
|
2021-08-22 04:52:56 -07:00
|
|
|
|
• `on_hunk` (callback):
|
|
|
|
|
Invoked for each hunk in the diff. Return a negative number
|
|
|
|
|
to cancel the callback for any remaining hunks.
|
|
|
|
|
Args:
|
|
|
|
|
• `start_a` (integer): Start line of hunk in {a}.
|
|
|
|
|
• `count_a` (integer): Hunk size in {a}.
|
|
|
|
|
• `start_b` (integer): Start line of hunk in {b}.
|
|
|
|
|
• `count_b` (integer): Hunk size in {b}.
|
|
|
|
|
• `result_type` (string): Form of the returned diff:
|
|
|
|
|
• "unified": (default) String in unified format.
|
|
|
|
|
• "indices": Array of hunk locations.
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Note: This option is ignored if `on_hunk` is used.
|
2022-11-04 02:07:22 -07:00
|
|
|
|
• `linematch` (boolean): Run linematch on the resulting hunks
|
|
|
|
|
from xdiff. Requires `result_type = indices`, ignored
|
|
|
|
|
otherwise.
|
2021-08-22 04:52:56 -07:00
|
|
|
|
• `algorithm` (string):
|
|
|
|
|
Diff algorithm to use. Values:
|
|
|
|
|
• "myers" the default algorithm
|
|
|
|
|
• "minimal" spend extra time to generate the
|
|
|
|
|
smallest possible diff
|
|
|
|
|
• "patience" patience diff algorithm
|
|
|
|
|
• "histogram" histogram diff algorithm
|
|
|
|
|
• `ctxlen` (integer): Context length
|
|
|
|
|
• `interhunkctxlen` (integer):
|
|
|
|
|
Inter hunk context length
|
|
|
|
|
• `ignore_whitespace` (boolean):
|
|
|
|
|
Ignore whitespace
|
|
|
|
|
• `ignore_whitespace_change` (boolean):
|
|
|
|
|
Ignore whitespace change
|
|
|
|
|
• `ignore_whitespace_change_at_eol` (boolean)
|
|
|
|
|
Ignore whitespace change at end-of-line.
|
|
|
|
|
• `ignore_cr_at_eol` (boolean)
|
|
|
|
|
Ignore carriage return at end-of-line
|
|
|
|
|
• `ignore_blank_lines` (boolean)
|
|
|
|
|
Ignore blank lines
|
|
|
|
|
• `indent_heuristic` (boolean):
|
|
|
|
|
Use the indent heuristic for the internal
|
|
|
|
|
diff library.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2021-08-22 04:52:56 -07:00
|
|
|
|
Return: ~
|
|
|
|
|
See {opts.result_type}. nil if {opts.on_hunk} is given.
|
|
|
|
|
|
2021-09-04 08:39:22 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
VIM.MPACK *lua-mpack*
|
|
|
|
|
|
2021-10-30 06:59:59 -07:00
|
|
|
|
The *vim.mpack* module provides encoding and decoding of Lua objects to and
|
|
|
|
|
from msgpack-encoded strings. Supports |vim.NIL| and |vim.empty_dict()|.
|
2021-09-04 08:39:22 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.mpack.encode({obj}) *vim.mpack.encode*
|
2021-10-30 06:59:59 -07:00
|
|
|
|
Encodes (or "packs") Lua object {obj} as msgpack in a Lua string.
|
2021-09-04 08:39:22 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.mpack.decode({str}) *vim.mpack.decode*
|
2021-10-30 06:59:59 -07:00
|
|
|
|
Decodes (or "unpacks") the msgpack-encoded {str} to a Lua object.
|
2021-09-04 08:39:22 -07:00
|
|
|
|
|
2021-12-25 12:36:56 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
2022-05-11 09:23:46 -07:00
|
|
|
|
VIM.SPELL *lua-spell*
|
2021-12-25 12:36:56 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.spell.check({str}) *vim.spell.check()*
|
2021-12-25 12:36:56 -07:00
|
|
|
|
Check {str} for spelling errors. Similar to the Vimscript function
|
|
|
|
|
|spellbadword()|.
|
|
|
|
|
|
|
|
|
|
Note: The behaviour of this function is dependent on: 'spelllang',
|
2022-05-11 09:23:46 -07:00
|
|
|
|
'spellfile', 'spellcapcheck' and 'spelloptions' which can all be local to
|
|
|
|
|
the buffer. Consider calling this with |nvim_buf_call()|.
|
2021-12-25 12:36:56 -07:00
|
|
|
|
|
|
|
|
|
Example: >
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
2021-12-25 12:36:56 -07:00
|
|
|
|
vim.spell.check("the quik brown fox")
|
2022-10-09 09:19:43 -07:00
|
|
|
|
=>
|
2021-12-25 12:36:56 -07:00
|
|
|
|
{
|
|
|
|
|
{'quik', 'bad', 4}
|
|
|
|
|
}
|
|
|
|
|
<
|
|
|
|
|
Parameters: ~
|
2022-10-09 09:19:43 -07:00
|
|
|
|
• {str} String to spell check.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2021-12-25 12:36:56 -07:00
|
|
|
|
Return: ~
|
|
|
|
|
List of tuples with three items:
|
|
|
|
|
- The badly spelled word.
|
|
|
|
|
- The type of the spelling error:
|
|
|
|
|
"bad" spelling mistake
|
|
|
|
|
"rare" rare word
|
|
|
|
|
"local" word only valid in another region
|
|
|
|
|
"caps" word should start with Capital
|
|
|
|
|
- The position in {str} where the word begins.
|
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
2022-05-11 09:23:46 -07:00
|
|
|
|
VIM *lua-builtin*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.api.{func}({...}) *vim.api*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Invokes Nvim |API| function {func} with arguments {...}.
|
|
|
|
|
Example: call the "nvim_get_current_line()" API function: >
|
|
|
|
|
print(tostring(vim.api.nvim_get_current_line()))
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.version() *vim.version*
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Gets the version of the current Nvim build.
|
2021-01-18 01:37:18 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.in_fast_event() *vim.in_fast_event()*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Returns true if the code is executing as part of a "fast" event handler,
|
|
|
|
|
where most of the API is disabled. These are low-level events (e.g.
|
|
|
|
|
|lua-loop-callbacks|) which can be invoked whenever Nvim polls for input.
|
2022-05-11 09:23:46 -07:00
|
|
|
|
When this is `false` most API functions are callable (but may be subject
|
2019-11-17 20:06:59 -07:00
|
|
|
|
to other restrictions such as |textlock|).
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.NIL *vim.NIL*
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Special value representing NIL in |RPC| and |v:null| in Vimscript
|
|
|
|
|
conversion, and similar cases. Lua `nil` cannot be used as part of a Lua
|
|
|
|
|
table representing a Dictionary or Array, because it is treated as
|
|
|
|
|
missing: `{"foo", nil}` is the same as `{"foo"}`.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
vim.empty_dict() *vim.empty_dict()*
|
|
|
|
|
Creates a special empty table (marked with a metatable), which Nvim to an
|
|
|
|
|
empty dictionary when translating Lua values to Vimscript or API types.
|
|
|
|
|
Nvim by default converts an empty table `{}` without this metatable to an
|
|
|
|
|
list/array.
|
2019-11-27 12:45:41 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Note: If numeric keys are present in the table, Nvim ignores the metatable
|
2021-09-14 10:20:33 -07:00
|
|
|
|
marker and converts the dict to a list/array anyway.
|
2019-11-27 12:45:41 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.rpcnotify({channel}, {method} [, {args}...]) *vim.rpcnotify()*
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Sends {event} to {channel} via |RPC| and returns immediately. If {channel}
|
|
|
|
|
is 0, the event is broadcast to all channels.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
This function also works in a fast callback |lua-loop-callbacks|.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
vim.rpcrequest({channel}, {method} [, {args}...]) *vim.rpcrequest()*
|
|
|
|
|
Sends a request to {channel} to invoke {method} via |RPC| and blocks until
|
|
|
|
|
a response is received.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2021-09-14 10:20:33 -07:00
|
|
|
|
Note: NIL values as part of the return value is represented as |vim.NIL|
|
|
|
|
|
special value
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.stricmp({a}, {b}) *vim.stricmp()*
|
|
|
|
|
Compares strings case-insensitively. Returns 0, 1 or -1 if strings are
|
2019-11-17 20:06:59 -07:00
|
|
|
|
equal, {a} is greater than {b} or {a} is lesser than {b}, respectively.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.str_utfindex({str} [, {index}]) *vim.str_utfindex()*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Convert byte index to UTF-32 and UTF-16 indices. If {index} is not
|
|
|
|
|
supplied, the length of the string is used. All indices are zero-based.
|
|
|
|
|
Returns two values: the UTF-32 and UTF-16 indices respectively.
|
|
|
|
|
|
|
|
|
|
Embedded NUL bytes are treated as terminating the string. Invalid UTF-8
|
|
|
|
|
bytes, and embedded surrogates are counted as one code point each. An
|
|
|
|
|
{index} in the middle of a UTF-8 sequence is rounded upwards to the end of
|
|
|
|
|
that sequence.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.str_byteindex({str}, {index} [, {use_utf16}]) *vim.str_byteindex()*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Convert UTF-32 or UTF-16 {index} to byte index. If {use_utf16} is not
|
|
|
|
|
supplied, it defaults to false (use UTF-32). Returns the byte index.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Invalid UTF-8 and NUL is treated like by |vim.str_byteindex()|.
|
|
|
|
|
An {index} in the middle of a UTF-16 sequence is rounded upwards to
|
|
|
|
|
the end of that sequence.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-08-24 06:41:31 -07:00
|
|
|
|
vim.iconv({str}, {from}, {to}[, {opts}]) *vim.iconv()*
|
|
|
|
|
The result is a String, which is the text {str} converted from
|
|
|
|
|
encoding {from} to encoding {to}. When the conversion fails `nil` is
|
|
|
|
|
returned. When some characters could not be converted they
|
|
|
|
|
are replaced with "?".
|
|
|
|
|
The encoding names are whatever the iconv() library function
|
|
|
|
|
can accept, see ":Man 3 iconv".
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-09 09:19:43 -07:00
|
|
|
|
• {str} (string) Text to convert
|
|
|
|
|
• {from} (string) Encoding of {str}
|
|
|
|
|
• {to} (string) Target encoding
|
2022-08-24 06:41:31 -07:00
|
|
|
|
|
|
|
|
|
Returns: ~
|
|
|
|
|
Converted string if conversion succeeds, `nil` otherwise.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.schedule({callback}) *vim.schedule()*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Schedules {callback} to be invoked soon by the main event-loop. Useful
|
|
|
|
|
to avoid |textlock| or other temporary restrictions.
|
|
|
|
|
|
2020-05-20 08:08:19 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.defer_fn({fn}, {timeout}) *vim.defer_fn*
|
|
|
|
|
Defers calling {fn} until {timeout} ms passes. Use to do a one-shot timer
|
2020-05-20 08:08:19 -07:00
|
|
|
|
that calls {fn}.
|
|
|
|
|
|
2022-09-25 16:58:27 -07:00
|
|
|
|
Note: The {fn} is |vim.schedule_wrap()|ped automatically, so API functions are
|
2020-07-07 01:55:40 -07:00
|
|
|
|
safe to call.
|
|
|
|
|
|
2020-05-20 08:08:19 -07:00
|
|
|
|
Parameters: ~
|
2022-10-09 09:19:43 -07:00
|
|
|
|
• {fn} Callback to call once {timeout} expires
|
|
|
|
|
• {timeout} Time in ms to wait before calling {fn}
|
2020-05-20 08:08:19 -07:00
|
|
|
|
|
|
|
|
|
Returns: ~
|
|
|
|
|
|vim.loop|.new_timer() object
|
|
|
|
|
|
2020-10-06 09:58:05 -07:00
|
|
|
|
vim.wait({time} [, {callback}, {interval}, {fast_only}]) *vim.wait()*
|
2020-05-20 08:08:19 -07:00
|
|
|
|
Wait for {time} in milliseconds until {callback} returns `true`.
|
|
|
|
|
|
|
|
|
|
Executes {callback} immediately and at approximately {interval}
|
|
|
|
|
milliseconds (default 200). Nvim still processes other events during
|
|
|
|
|
this time.
|
|
|
|
|
|
2020-10-06 09:58:05 -07:00
|
|
|
|
Parameters: ~
|
2022-10-09 09:19:43 -07:00
|
|
|
|
• {time} Number of milliseconds to wait
|
|
|
|
|
• {callback} Optional callback. Waits until {callback} returns true
|
|
|
|
|
• {interval} (Approximate) number of milliseconds to wait between polls
|
|
|
|
|
• {fast_only} If true, only |api-fast| events will be processed.
|
2020-10-06 09:58:05 -07:00
|
|
|
|
If called from while in an |api-fast| event, will
|
|
|
|
|
automatically be set to `true`.
|
2020-05-20 08:08:19 -07:00
|
|
|
|
|
|
|
|
|
Returns: ~
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
Examples: >
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
-- 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
|
|
|
|
|
<
|
|
|
|
|
|
2022-06-30 00:26:31 -07:00
|
|
|
|
vim.ui_attach({ns}, {options}, {callback}) *vim.ui_attach()*
|
|
|
|
|
Attach to ui events, similar to |nvim_ui_attach()| but receive events
|
|
|
|
|
as lua callback. Can be used to implement screen elements like
|
|
|
|
|
popupmenu or message handling in lua.
|
|
|
|
|
|
|
|
|
|
{options} should be a dictionary-like table, where `ext_...` options should
|
|
|
|
|
be set to true to receive events for the respective external element.
|
|
|
|
|
|
|
|
|
|
{callback} receives event name plus additional parameters. See |ui-popupmenu|
|
|
|
|
|
and the sections below for event format for respective events.
|
|
|
|
|
|
2022-09-28 07:16:02 -07:00
|
|
|
|
WARNING: This api is considered experimental. Usability will vary for
|
|
|
|
|
different screen elements. In particular `ext_messages` behavior is subject
|
|
|
|
|
to further changes and usability improvements. This is expected to be
|
|
|
|
|
used to handle messages when setting 'cmdheight' to zero (which is
|
|
|
|
|
likewise experimental).
|
|
|
|
|
|
2022-06-30 00:26:31 -07:00
|
|
|
|
Example (stub for a |ui-popupmenu| implementation): >
|
|
|
|
|
|
|
|
|
|
ns = vim.api.nvim_create_namespace('my_fancy_pum')
|
|
|
|
|
|
|
|
|
|
vim.ui_attach(ns, {ext_popupmenu=true}, function(event, ...)
|
|
|
|
|
if event == "popupmenu_show" then
|
|
|
|
|
local items, selected, row, col, grid = ...
|
|
|
|
|
print("display pum ", #items)
|
|
|
|
|
elseif event == "popupmenu_select" then
|
|
|
|
|
local selected = ...
|
|
|
|
|
print("selected", selected)
|
|
|
|
|
elseif event == "popupmenu_hide" then
|
|
|
|
|
print("FIN")
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
vim.ui_detach({ns}) *vim.ui_detach()*
|
|
|
|
|
Detach a callback previously attached with |vim.ui_attach()| for the
|
|
|
|
|
given namespace {ns}.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.type_idx *vim.type_idx*
|
|
|
|
|
Type index for use in |lua-special-tbl|. Specifying one of the values from
|
2021-09-14 10:20:33 -07:00
|
|
|
|
|vim.types| allows typing the empty table (it is unclear whether empty Lua
|
|
|
|
|
table represents empty list or empty array) and forcing integral numbers
|
2022-05-11 09:23:46 -07:00
|
|
|
|
to be |Float|. See |lua-special-tbl| for more details.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.val_idx *vim.val_idx*
|
|
|
|
|
Value index for tables representing |Float|s. A table representing
|
2021-09-14 10:20:33 -07:00
|
|
|
|
floating-point value 1.0 looks like this: >
|
2019-11-17 20:06:59 -07:00
|
|
|
|
{
|
|
|
|
|
[vim.type_idx] = vim.types.float,
|
|
|
|
|
[vim.val_idx] = 1.0,
|
|
|
|
|
}
|
2021-09-14 10:20:33 -07:00
|
|
|
|
< See also |vim.type_idx| and |lua-special-tbl|.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.types *vim.types*
|
|
|
|
|
Table with possible values for |vim.type_idx|. Contains two sets of
|
2021-09-14 10:20:33 -07:00
|
|
|
|
key-value pairs: first maps possible values for |vim.type_idx| to
|
|
|
|
|
human-readable strings, second maps human-readable type names to values
|
2022-05-11 09:23:46 -07:00
|
|
|
|
for |vim.type_idx|. Currently contains pairs for `float`, `array` and
|
2021-09-14 10:20:33 -07:00
|
|
|
|
`dictionary` types.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Note: One must expect that values corresponding to `vim.types.float`,
|
2021-09-14 10:20:33 -07:00
|
|
|
|
`vim.types.array` and `vim.types.dictionary` fall under only two following
|
|
|
|
|
assumptions:
|
2022-05-11 09:23:46 -07:00
|
|
|
|
1. Value may serve both as a key and as a value in a table. Given the
|
2021-09-14 10:20:33 -07:00
|
|
|
|
properties of Lua tables this basically means “value is not `nil`”.
|
|
|
|
|
2. For each value in `vim.types` table `vim.types[vim.types[value]]` is the
|
|
|
|
|
same as `value`.
|
|
|
|
|
No other restrictions are put on types, and it is not guaranteed that
|
|
|
|
|
values corresponding to `vim.types.float`, `vim.types.array` and
|
|
|
|
|
`vim.types.dictionary` will not change or that `vim.types` table will only
|
|
|
|
|
contain values for these three types.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2021-11-25 12:06:42 -07:00
|
|
|
|
*log_levels* *vim.log.levels*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Log levels are one of the values defined in `vim.log.levels`:
|
2021-12-28 10:15:16 -07:00
|
|
|
|
|
2021-11-25 12:06:42 -07:00
|
|
|
|
vim.log.levels.DEBUG
|
|
|
|
|
vim.log.levels.ERROR
|
|
|
|
|
vim.log.levels.INFO
|
|
|
|
|
vim.log.levels.TRACE
|
|
|
|
|
vim.log.levels.WARN
|
2022-05-03 07:49:23 -07:00
|
|
|
|
vim.log.levels.OFF
|
2021-12-28 10:15:16 -07:00
|
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
|
------------------------------------------------------------------------------
|
2022-05-11 09:23:46 -07:00
|
|
|
|
LUA-VIMSCRIPT BRIDGE *lua-vimscript*
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Nvim Lua provides an interface to Vimscript variables and functions, and
|
|
|
|
|
editor commands and options.
|
2022-10-09 05:21:52 -07:00
|
|
|
|
|
2021-04-09 10:36:23 -07:00
|
|
|
|
See also https://github.com/nanotee/nvim-lua-guide.
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.call({func}, {...}) *vim.call()*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Invokes |vim-function| or |user-function| {func} with arguments {...}.
|
|
|
|
|
See also |vim.fn|.
|
|
|
|
|
Equivalent to: >
|
|
|
|
|
vim.fn[func]({...})
|
2022-05-12 06:34:38 -07:00
|
|
|
|
|
|
|
|
|
vim.cmd({command})
|
|
|
|
|
See |vim.cmd()|.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.fn.{func}({...}) *vim.fn*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Invokes |vim-function| or |user-function| {func} with arguments {...}.
|
|
|
|
|
To call autoload functions, use the syntax: >
|
|
|
|
|
vim.fn['some#function']({...})
|
2020-05-17 20:29:34 -07:00
|
|
|
|
<
|
2021-09-10 06:59:17 -07:00
|
|
|
|
Unlike vim.api.|nvim_call_function()| this converts directly between Vim
|
2020-08-31 00:51:35 -07:00
|
|
|
|
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.
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Note: |v:null| values as part of the return value is represented as
|
|
|
|
|
|vim.NIL| special value
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Note: vim.fn keys are generated lazily, thus `pairs(vim.fn)` only
|
|
|
|
|
enumerates functions that were called at least once.
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2022-04-29 09:26:57 -07:00
|
|
|
|
Note: The majority of functions cannot run in |api-fast| callbacks with some
|
|
|
|
|
undocumented exceptions which are allowed.
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
*lua-vim-variables*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
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.
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Example: >
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2020-08-31 00:51:35 -07:00
|
|
|
|
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.
|
2021-09-23 07:00:25 -07:00
|
|
|
|
vim.b[2].foo = 6 -- Set b:foo for buffer 2
|
2022-05-11 09:23:46 -07:00
|
|
|
|
<
|
2022-09-22 06:17:49 -07:00
|
|
|
|
|
|
|
|
|
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: >
|
|
|
|
|
|
|
|
|
|
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 --
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.g *vim.g*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Global (|g:|) editor variables.
|
|
|
|
|
Key with no value returns `nil`.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.b *vim.b*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Buffer-scoped (|b:|) variables for the current buffer.
|
2021-09-23 07:00:25 -07:00
|
|
|
|
Invalid or unset key returns `nil`. Can be indexed with
|
|
|
|
|
an integer to access variables for a specific buffer.
|
2020-08-31 00:51:35 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.w *vim.w*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Window-scoped (|w:|) variables for the current window.
|
2021-09-23 07:00:25 -07:00
|
|
|
|
Invalid or unset key returns `nil`. Can be indexed with
|
|
|
|
|
an integer to access variables for a specific window.
|
2020-08-31 00:51:35 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.t *vim.t*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Tabpage-scoped (|t:|) variables for the current tabpage.
|
2021-09-23 07:00:25 -07:00
|
|
|
|
Invalid or unset key returns `nil`. Can be indexed with
|
|
|
|
|
an integer to access variables for a specific tabpage.
|
2020-08-31 00:51:35 -07:00
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.v *vim.v*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
|v:| variables.
|
|
|
|
|
Invalid or unset key returns `nil`.
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
vim.env *vim.env*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Environment variables defined in the editor session.
|
|
|
|
|
See |expand-env| and |:let-environment| for the Vimscript behavior.
|
|
|
|
|
Invalid or unset key returns `nil`.
|
|
|
|
|
Example: >
|
|
|
|
|
vim.env.FOO = 'bar'
|
|
|
|
|
print(vim.env.TERM)
|
|
|
|
|
<
|
2020-05-17 20:29:34 -07:00
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
*lua-options*
|
2021-05-28 08:24:48 -07:00
|
|
|
|
*lua-vim-options*
|
|
|
|
|
*lua-vim-set*
|
|
|
|
|
*lua-vim-setlocal*
|
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
Vim options can be accessed through |vim.o|, which behaves like Vimscript
|
|
|
|
|
|:set|.
|
2021-05-28 08:24:48 -07:00
|
|
|
|
|
|
|
|
|
Examples: ~
|
|
|
|
|
|
|
|
|
|
To set a boolean toggle:
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Vimscript: `set number`
|
|
|
|
|
Lua: `vim.o.number = true`
|
2021-05-28 08:24:48 -07:00
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
To set a string value:
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Vimscript: `set wildignore=*.o,*.a,__pycache__`
|
|
|
|
|
Lua: `vim.o.wildignore = '*.o,*.a,__pycache__'`
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
2022-09-22 06:17:49 -07:00
|
|
|
|
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|.
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
|
|
|
|
vim.o *vim.o*
|
2022-09-25 16:58:27 -07:00
|
|
|
|
Get or set |options|. Like `:set`. Invalid key is an error.
|
2022-09-22 06:17:49 -07:00
|
|
|
|
|
|
|
|
|
Note: this works on both buffer-scoped and window-scoped options using the
|
|
|
|
|
current buffer and window.
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
|
|
|
|
Example: >
|
|
|
|
|
vim.o.cmdheight = 4
|
|
|
|
|
print(vim.o.columns)
|
|
|
|
|
print(vim.o.foo) -- error: invalid key
|
|
|
|
|
<
|
|
|
|
|
vim.go *vim.go*
|
2022-09-25 16:58:27 -07:00
|
|
|
|
Get or set global |options|. Like `:setglobal`. Invalid key is
|
2022-09-22 06:17:49 -07:00
|
|
|
|
an error.
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Note: this is different from |vim.o| because this accesses the global
|
|
|
|
|
option value and thus is mostly useful for use with |global-local|
|
|
|
|
|
options.
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
|
|
|
|
Example: >
|
|
|
|
|
vim.go.cmdheight = 4
|
|
|
|
|
print(vim.go.columns)
|
|
|
|
|
print(vim.go.bar) -- error: invalid key
|
|
|
|
|
<
|
|
|
|
|
vim.bo[{bufnr}] *vim.bo*
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Get or set buffer-scoped |options| for the buffer with number {bufnr}.
|
|
|
|
|
Like `:set` and `:setlocal`. If [{bufnr}] is omitted then the current
|
|
|
|
|
buffer is used. Invalid {bufnr} or key is an error.
|
2021-05-28 08:24:48 -07:00
|
|
|
|
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Note: this is equivalent to both `:set` and `:setlocal`.
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
|
|
|
|
Example: >
|
|
|
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
|
|
|
vim.bo[bufnr].buflisted = true -- same as vim.bo.buflisted = true
|
|
|
|
|
print(vim.bo.comments)
|
|
|
|
|
print(vim.bo.baz) -- error: invalid key
|
|
|
|
|
<
|
|
|
|
|
vim.wo[{winid}] *vim.wo*
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Get or set window-scoped |options| for the window with handle {winid}.
|
|
|
|
|
Like `:set`. If [{winid}] is omitted then the current window is used.
|
|
|
|
|
Invalid {winid} or key is an error.
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
2022-09-22 06:17:49 -07:00
|
|
|
|
Note: this does not access |local-options| (`:setlocal`) instead use: >
|
|
|
|
|
nvim_get_option_value(OPTION, { scope = 'local', win = winid })
|
|
|
|
|
nvim_set_option_value(OPTION, VALUE, { scope = 'local', win = winid }
|
|
|
|
|
<
|
2022-08-30 05:46:38 -07:00
|
|
|
|
Example: >
|
|
|
|
|
local winid = vim.api.nvim_get_current_win()
|
|
|
|
|
vim.wo[winid].number = true -- same as vim.wo.number = true
|
|
|
|
|
print(vim.wo.foldmarker)
|
|
|
|
|
print(vim.wo.quux) -- error: invalid key
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*lua-vim-opt*
|
|
|
|
|
*lua-vim-optlocal*
|
|
|
|
|
*lua-vim-optglobal*
|
|
|
|
|
*vim.opt*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A special interface |vim.opt| exists for conveniently interacting with list-
|
|
|
|
|
and map-style option from Lua: It allows accessing them as Lua tables and
|
|
|
|
|
offers object-oriented method for adding and removing entries.
|
|
|
|
|
|
|
|
|
|
Examples: ~
|
|
|
|
|
|
|
|
|
|
The following methods of setting a list-style option are equivalent:
|
|
|
|
|
In Vimscript:
|
|
|
|
|
`set wildignore=*.o,*.a,__pycache__`
|
|
|
|
|
|
|
|
|
|
In Lua using `vim.o`:
|
|
|
|
|
`vim.o.wildignore = '*.o,*.a,__pycache__'`
|
|
|
|
|
|
|
|
|
|
In Lua using `vim.opt`:
|
2021-05-28 08:24:48 -07:00
|
|
|
|
`vim.opt.wildignore = { '*.o', '*.a', '__pycache__' }`
|
|
|
|
|
|
|
|
|
|
To replicate the behavior of |:set+=|, use: >
|
|
|
|
|
|
|
|
|
|
vim.opt.wildignore:append { "*.pyc", "node_modules" }
|
|
|
|
|
<
|
|
|
|
|
To replicate the behavior of |:set^=|, use: >
|
|
|
|
|
|
|
|
|
|
vim.opt.wildignore:prepend { "new_first_value" }
|
|
|
|
|
<
|
|
|
|
|
To replicate the behavior of |:set-=|, use: >
|
|
|
|
|
|
|
|
|
|
vim.opt.wildignore:remove { "node_modules" }
|
|
|
|
|
<
|
2022-08-30 05:46:38 -07:00
|
|
|
|
The following methods of setting a map-style option are equivalent:
|
2021-09-14 10:20:33 -07:00
|
|
|
|
In Vimscript:
|
2021-05-28 08:24:48 -07:00
|
|
|
|
`set listchars=space:_,tab:>~`
|
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
In Lua using `vim.o`:
|
|
|
|
|
`vim.o.listchars = 'space:_,tab:>~'`
|
|
|
|
|
|
|
|
|
|
In Lua using `vim.opt`:
|
2021-05-28 08:24:48 -07:00
|
|
|
|
`vim.opt.listchars = { space = '_', tab = '>~' }`
|
|
|
|
|
|
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
Note that |vim.opt| returns an `Option` object, not the value of the option,
|
2022-09-25 16:58:27 -07:00
|
|
|
|
which is accessed through |vim.opt:get()|:
|
2022-08-30 05:46:38 -07:00
|
|
|
|
|
|
|
|
|
Examples: ~
|
|
|
|
|
|
|
|
|
|
The following methods of getting a list-style option are equivalent:
|
|
|
|
|
In Vimscript:
|
|
|
|
|
`echo wildignore`
|
|
|
|
|
|
|
|
|
|
In Lua using `vim.o`:
|
|
|
|
|
`print(vim.o.wildignore)`
|
|
|
|
|
|
|
|
|
|
In Lua using `vim.opt`:
|
|
|
|
|
`vim.pretty_print(vim.opt.wildignore:get())`
|
|
|
|
|
|
|
|
|
|
|
2022-09-25 16:58:27 -07:00
|
|
|
|
In any of the above examples, to replicate the behavior |:setlocal|, use
|
|
|
|
|
`vim.opt_local`. Additionally, to replicate the behavior of |:setglobal|, use
|
2021-05-28 08:24:48 -07:00
|
|
|
|
`vim.opt_global`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*vim.opt:get()*
|
|
|
|
|
Option:get()
|
|
|
|
|
|
|
|
|
|
Returns a lua-representation of the option. Boolean, number and string
|
|
|
|
|
values will be returned in exactly the same fashion.
|
|
|
|
|
|
|
|
|
|
For values that are comma-separated lists, an array will be returned with
|
|
|
|
|
the values as entries in the array: >
|
|
|
|
|
vim.cmd [[set wildignore=*.pyc,*.o]]
|
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
vim.pretty_print(vim.opt.wildignore:get())
|
2021-05-28 08:24:48 -07:00
|
|
|
|
-- { "*.pyc", "*.o", }
|
|
|
|
|
|
|
|
|
|
for _, ignore_pattern in ipairs(vim.opt.wildignore:get()) do
|
|
|
|
|
print("Will ignore:", ignore_pattern)
|
|
|
|
|
end
|
|
|
|
|
-- Will ignore: *.pyc
|
|
|
|
|
-- Will ignore: *.o
|
|
|
|
|
<
|
|
|
|
|
For values that are comma-separated maps, a table will be returned with
|
|
|
|
|
the names as keys and the values as entries: >
|
|
|
|
|
vim.cmd [[set listchars=space:_,tab:>~]]
|
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
vim.pretty_print(vim.opt.listchars:get())
|
2021-05-28 08:24:48 -07:00
|
|
|
|
-- { space = "_", tab = ">~", }
|
|
|
|
|
|
|
|
|
|
for char, representation in pairs(vim.opt.listchars:get()) do
|
2022-10-09 09:19:43 -07:00
|
|
|
|
print(char, "=>", representation)
|
2021-05-28 08:24:48 -07:00
|
|
|
|
end
|
|
|
|
|
<
|
|
|
|
|
For values that are lists of flags, a set will be returned with the flags
|
|
|
|
|
as keys and `true` as entries. >
|
|
|
|
|
vim.cmd [[set formatoptions=njtcroql]]
|
|
|
|
|
|
2022-08-30 05:46:38 -07:00
|
|
|
|
vim.pretty_print(vim.opt.formatoptions:get())
|
2021-05-28 08:24:48 -07:00
|
|
|
|
-- { n = true, j = true, c = true, ... }
|
|
|
|
|
|
|
|
|
|
local format_opts = vim.opt.formatoptions:get()
|
|
|
|
|
if format_opts.j then
|
|
|
|
|
print("J is enabled!")
|
|
|
|
|
end
|
|
|
|
|
<
|
|
|
|
|
*vim.opt:append()*
|
|
|
|
|
Option:append(value)
|
|
|
|
|
|
|
|
|
|
Append a value to string-style options. See |:set+=|
|
|
|
|
|
|
|
|
|
|
These are equivalent:
|
|
|
|
|
`vim.opt.formatoptions:append('j')`
|
|
|
|
|
`vim.opt.formatoptions = vim.opt.formatoptions + 'j'`
|
|
|
|
|
|
|
|
|
|
*vim.opt:prepend()*
|
|
|
|
|
Option:prepend(value)
|
|
|
|
|
|
|
|
|
|
Prepend a value to string-style options. See |:set^=|
|
|
|
|
|
|
|
|
|
|
These are equivalent:
|
|
|
|
|
`vim.opt.wildignore:prepend('*.o')`
|
|
|
|
|
`vim.opt.wildignore = vim.opt.wildignore ^ '*.o'`
|
|
|
|
|
|
|
|
|
|
*vim.opt:remove()*
|
|
|
|
|
Option:remove(value)
|
|
|
|
|
|
2021-05-29 21:09:30 -07:00
|
|
|
|
Remove a value from string-style options. See |:set-=|
|
2021-05-28 08:24:48 -07:00
|
|
|
|
|
|
|
|
|
These are equivalent:
|
|
|
|
|
`vim.opt.wildignore:remove('*.pyc')`
|
|
|
|
|
`vim.opt.wildignore = vim.opt.wildignore - '*.pyc'`
|
|
|
|
|
|
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: vim *lua-vim*
|
|
|
|
|
|
2022-05-12 06:34:38 -07:00
|
|
|
|
cmd({command}) *vim.cmd()*
|
|
|
|
|
Execute Vim script commands.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-07-20 04:29:24 -07:00
|
|
|
|
Note that `vim.cmd` can be indexed with a command name to return a
|
|
|
|
|
callable function to the command.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-12 06:34:38 -07:00
|
|
|
|
Example: >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-12 06:34:38 -07:00
|
|
|
|
vim.cmd('echo 42')
|
|
|
|
|
vim.cmd([[
|
|
|
|
|
augroup My_group
|
|
|
|
|
autocmd!
|
|
|
|
|
autocmd FileType c setlocal cindent
|
|
|
|
|
augroup END
|
|
|
|
|
]])
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-07-20 04:29:24 -07:00
|
|
|
|
-- Ex command :echo "foo"
|
|
|
|
|
-- Note string literals need to be double quoted.
|
|
|
|
|
vim.cmd('echo "foo"')
|
|
|
|
|
vim.cmd { cmd = 'echo', args = { '"foo"' } }
|
|
|
|
|
vim.cmd.echo({ args = { '"foo"' } })
|
|
|
|
|
vim.cmd.echo('"foo"')
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-07-20 04:29:24 -07:00
|
|
|
|
-- Ex command :write! myfile.txt
|
|
|
|
|
vim.cmd('write! myfile.txt')
|
|
|
|
|
vim.cmd { cmd = 'write', args = { "myfile.txt" }, bang = true }
|
|
|
|
|
vim.cmd.write { args = { "myfile.txt" }, bang = true }
|
|
|
|
|
vim.cmd.write { "myfile.txt", bang = true }
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-07-20 04:29:24 -07:00
|
|
|
|
-- Ex command :colorscheme blue
|
|
|
|
|
vim.cmd('colorscheme blue')
|
|
|
|
|
vim.cmd.colorscheme('blue')
|
2022-05-12 06:34:38 -07:00
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {command} string|table Command(s) to execute. If a string, executes
|
2022-05-12 06:34:38 -07:00
|
|
|
|
multiple lines of Vim script at once. In this case, it is
|
|
|
|
|
an alias to |nvim_exec()|, where `output` is set to false.
|
|
|
|
|
Thus it works identical to |:source|. If a table, executes
|
|
|
|
|
a single command. In this case, it is an alias to
|
|
|
|
|
|nvim_cmd()| where `opts` is empty.
|
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|ex-cmd-index|
|
|
|
|
|
|
2022-03-20 11:00:30 -07:00
|
|
|
|
*vim.connection_failure_errmsg()*
|
|
|
|
|
connection_failure_errmsg({consequence})
|
|
|
|
|
TODO: Documentation
|
|
|
|
|
|
2021-05-31 10:47:51 -07:00
|
|
|
|
defer_fn({fn}, {timeout}) *vim.defer_fn()*
|
|
|
|
|
Defers calling `fn` until `timeout` ms passes.
|
|
|
|
|
|
2022-09-25 16:58:27 -07:00
|
|
|
|
Use to do a one-shot timer that calls `fn` Note: The {fn} is |vim.schedule_wrap()|ped automatically, so API functions
|
|
|
|
|
are safe to call.
|
2021-05-31 10:47:51 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
• {fn} (function) Callback to call once `timeout` expires
|
|
|
|
|
• {timeout} integer Number of milliseconds to wait before calling `fn`
|
2021-05-31 10:47:51 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
(table) timer luv timer object
|
2021-05-31 10:47:51 -07:00
|
|
|
|
|
2022-05-15 18:07:36 -07:00
|
|
|
|
*vim.deprecate()*
|
|
|
|
|
deprecate({name}, {alternative}, {version}, {plugin}, {backtrace})
|
2022-05-03 06:42:41 -07:00
|
|
|
|
Display a deprecation notification to the user.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-03 06:42:41 -07:00
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {name} string Deprecated function.
|
|
|
|
|
• {alternative} (string|nil) Preferred alternative function.
|
|
|
|
|
• {version} string Version in which the deprecated function will be
|
2022-05-03 06:42:41 -07:00
|
|
|
|
removed.
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {plugin} string|nil Plugin name that the function will be
|
2022-05-03 06:42:41 -07:00
|
|
|
|
removed from. Defaults to "Nvim".
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {backtrace} boolean|nil Prints backtrace. Defaults to true.
|
2022-05-03 06:42:41 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
inspect({object}, {options}) *vim.inspect()*
|
2022-10-09 05:21:52 -07:00
|
|
|
|
Gets a human-readable representation of the given object.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
https://github.com/kikito/inspect.lua
|
|
|
|
|
https://github.com/mpeterv/vinspect
|
|
|
|
|
|
2022-01-06 11:10:56 -07:00
|
|
|
|
notify({msg}, {level}, {opts}) *vim.notify()*
|
|
|
|
|
Display a notification to the user.
|
2021-08-22 13:55:28 -07:00
|
|
|
|
|
2022-01-06 11:10:56 -07:00
|
|
|
|
This function can be overridden by plugins to display notifications using
|
|
|
|
|
a custom provider (such as the system notification provider). By default,
|
|
|
|
|
writes to |:messages|.
|
2021-05-31 10:47:51 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {msg} (string) Content of the notification to show to the user.
|
|
|
|
|
• {level} (number|nil) One of the values from |vim.log.levels|.
|
|
|
|
|
• {opts} (table|nil) Optional parameters. Unused by default.
|
2021-05-31 10:47:51 -07:00
|
|
|
|
|
2022-01-06 11:10:56 -07:00
|
|
|
|
notify_once({msg}, {level}, {opts}) *vim.notify_once()*
|
|
|
|
|
Display a notification only one time.
|
|
|
|
|
|
|
|
|
|
Like |vim.notify()|, but subsequent calls with the same message will not
|
|
|
|
|
display a notification.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {msg} (string) Content of the notification to show to the user.
|
|
|
|
|
• {level} (number|nil) One of the values from |vim.log.levels|.
|
|
|
|
|
• {opts} (table|nil) Optional parameters. Unused by default.
|
2021-08-22 13:55:28 -07:00
|
|
|
|
|
2022-05-15 18:07:36 -07:00
|
|
|
|
Return: ~
|
|
|
|
|
(boolean) true if message was displayed, else false
|
|
|
|
|
|
2021-10-05 10:48:48 -07:00
|
|
|
|
on_key({fn}, {ns_id}) *vim.on_key()*
|
|
|
|
|
Adds Lua function {fn} with namespace id {ns_id} as a listener to every,
|
|
|
|
|
yes every, input key.
|
|
|
|
|
|
|
|
|
|
The Nvim command-line option |-w| is related but does not support
|
|
|
|
|
callbacks and cannot be toggled dynamically.
|
|
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
{fn} will not be cleared by |nvim_buf_clear_namespace()|
|
|
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
{fn} will receive the keys after mappings have been evaluated
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
• {fn} (function) Callback function. It should take one string
|
2021-10-05 10:48:48 -07:00
|
|
|
|
argument. On each key press, Nvim passes the key char to
|
|
|
|
|
fn(). |i_CTRL-V| If {fn} is nil, it removes the callback for
|
|
|
|
|
the associated {ns_id}
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {ns_id} number? Namespace ID. If nil or 0, generates and returns a
|
2021-11-28 04:33:44 -07:00
|
|
|
|
new |nvim_create_namespace()| id.
|
2021-10-05 10:48:48 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(number) Namespace id associated with {fn}. Or count of all callbacks
|
|
|
|
|
if on_key() is called without arguments.
|
2021-10-05 10:48:48 -07:00
|
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
{fn} will be removed if an error occurs while calling.
|
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
paste({lines}, {phase}) *vim.paste()*
|
|
|
|
|
Paste handler, invoked by |nvim_paste()| when a conforming UI (such as the
|
|
|
|
|
|TUI|) pastes text into the editor.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Example: To remove ANSI color codes when pasting: >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
vim.paste = (function(overridden)
|
|
|
|
|
return function(lines, phase)
|
|
|
|
|
for i,line in ipairs(lines) do
|
|
|
|
|
-- Scrub ANSI color codes from paste input.
|
|
|
|
|
lines[i] = line:gsub('\27%[[0-9;mK]+', '')
|
|
|
|
|
end
|
|
|
|
|
overridden(lines, phase)
|
|
|
|
|
end
|
|
|
|
|
end)(vim.paste)
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
• {lines} string[] # |readfile()|-style list of lines to paste.
|
|
|
|
|
|channel-lines|
|
|
|
|
|
• {phase} paste_phase -1: "non-streaming" paste: the call contains all
|
|
|
|
|
lines. If paste is "streamed", `phase` indicates the stream state:
|
2019-11-17 20:06:59 -07:00
|
|
|
|
• 1: starts the paste (exactly once)
|
|
|
|
|
• 2: continues the paste (zero or more times)
|
|
|
|
|
• 3: ends the paste (exactly once)
|
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
(boolean) # false if client should cancel the paste.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
|paste| @alias paste_phase -1 | 1 | 2 | 3
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-01-06 11:42:31 -07:00
|
|
|
|
pretty_print({...}) *vim.pretty_print()*
|
|
|
|
|
Prints given arguments in human-readable format. Example: >
|
|
|
|
|
-- Print highlight group Normal and store it's contents in a variable.
|
|
|
|
|
local hl_normal = vim.pretty_print(vim.api.nvim_get_hl_by_name("Normal", true))
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
any # given arguments.
|
2022-01-06 11:42:31 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|vim.inspect()|
|
|
|
|
|
|
2021-05-31 10:47:51 -07:00
|
|
|
|
region({bufnr}, {pos1}, {pos2}, {regtype}, {inclusive}) *vim.region()*
|
|
|
|
|
Get a table of lines with start, end columns for a region marked by two
|
|
|
|
|
points
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {bufnr} (number) of buffer
|
2022-10-05 04:21:45 -07:00
|
|
|
|
• {pos1} integer[] (line, column) tuple marking beginning of
|
|
|
|
|
region
|
|
|
|
|
• {pos2} integer[] (line, column) tuple marking end of region
|
|
|
|
|
• {regtype} (string) type of selection, see |setreg()|
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {inclusive} (boolean) indicating whether the selection is
|
2021-05-31 10:47:51 -07:00
|
|
|
|
end-inclusive
|
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-10-05 04:21:45 -07:00
|
|
|
|
table<integer, {}> region lua table of the form {linenr =
|
|
|
|
|
{startcol,endcol}}
|
2021-05-31 10:47:51 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
schedule_wrap({cb}) *vim.schedule_wrap()*
|
|
|
|
|
Defers callback `cb` until the Nvim API is safe to call.
|
|
|
|
|
|
2022-10-05 04:21:45 -07:00
|
|
|
|
Parameters: ~
|
|
|
|
|
• {cb} (function)
|
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(function)
|
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
See also: ~
|
|
|
|
|
|lua-loop-callbacks|
|
|
|
|
|
|vim.schedule()|
|
|
|
|
|
|vim.in_fast_event()|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
deep_equal({a}, {b}) *vim.deep_equal()*
|
2021-09-10 06:22:40 -07:00
|
|
|
|
Deep compare values for equality
|
|
|
|
|
|
2022-05-11 09:23:46 -07:00
|
|
|
|
Tables are compared recursively unless they both provide the `eq` metamethod. All other types are compared using the equality `==` operator.
|
2021-09-10 06:22:40 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {a} any First value
|
|
|
|
|
• {b} any Second value
|
2021-09-10 06:22:40 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if values are equals, else `false`
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
deepcopy({orig}) *vim.deepcopy()*
|
|
|
|
|
Returns a deep copy of the given object. Non-table objects are copied as
|
|
|
|
|
in a typical Lua assignment, whereas table objects are copied recursively.
|
2020-04-18 16:04:37 -07:00
|
|
|
|
Functions are naively copied, so functions in the copied table point to
|
|
|
|
|
the same functions as those in the input table. Userdata and threads are
|
|
|
|
|
not copied and will throw an error.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {orig} (table) Table to copy
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(table) Table of copied keys and (nested) values.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-09-06 23:39:56 -07:00
|
|
|
|
defaulttable({create}) *vim.defaulttable()*
|
|
|
|
|
Creates a table whose members are automatically created when accessed, if
|
|
|
|
|
they don't already exist.
|
|
|
|
|
|
|
|
|
|
They mimic defaultdict in python.
|
|
|
|
|
|
2022-09-14 02:08:31 -07:00
|
|
|
|
If {create} is `nil`, this will create a defaulttable whose constructor
|
2022-09-06 23:39:56 -07:00
|
|
|
|
function is this function, effectively allowing to create nested tables on
|
|
|
|
|
the fly:
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
local a = vim.defaulttable()
|
|
|
|
|
a.b.c = 1
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {create} (function|nil) The function called to create a missing
|
2022-09-06 23:39:56 -07:00
|
|
|
|
value.
|
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(table) Empty table with metamethod
|
|
|
|
|
|
2020-01-13 00:41:55 -07:00
|
|
|
|
endswith({s}, {suffix}) *vim.endswith()*
|
2022-03-13 05:48:14 -07:00
|
|
|
|
Tests if `s` ends with `suffix`.
|
2020-01-13 00:41:55 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {s} (string) String
|
|
|
|
|
• {suffix} (string) Suffix to match
|
2020-01-13 00:41:55 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if `suffix` is a suffix of `s`
|
2020-01-13 00:41:55 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
gsplit({s}, {sep}, {plain}) *vim.gsplit()*
|
|
|
|
|
Splits a string at each instance of a separator.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {s} (string) String to split
|
|
|
|
|
• {sep} (string) Separator or pattern
|
2022-10-24 05:53:53 -07:00
|
|
|
|
• {plain} (boolean|nil) If `true` use `sep` literally (passed to
|
2022-05-12 07:02:46 -07:00
|
|
|
|
string.find)
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
(function) Iterator over the split components
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|vim.split()|
|
|
|
|
|
https://www.lua.org/pil/20.2.html
|
|
|
|
|
http://lua-users.org/wiki/StringLibraryTutorial
|
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
is_callable({f}) *vim.is_callable()*
|
|
|
|
|
Returns true if object `f` can be called as a function.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {f} any Any object
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if `f` is callable, else `false`
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
list_extend({dst}, {src}, {start}, {finish}) *vim.list_extend()*
|
|
|
|
|
Extends a list-like table with the values of another list-like table.
|
|
|
|
|
|
|
|
|
|
NOTE: This mutates dst!
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {dst} (table) List which will be modified and appended to
|
|
|
|
|
• {src} (table) List from which values will be inserted
|
2022-09-28 04:22:08 -07:00
|
|
|
|
• {start} (number|nil) Start index on src. Defaults to 1
|
|
|
|
|
• {finish} (number|nil) Final index on src. Defaults to `#src`
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(table) dst
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|vim.tbl_extend()|
|
|
|
|
|
|
2021-03-11 08:11:11 -07:00
|
|
|
|
list_slice({list}, {start}, {finish}) *vim.list_slice()*
|
|
|
|
|
Creates a copy of a table containing only elements from start to end
|
|
|
|
|
(inclusive)
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
• {list} (list) Table
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {start} (number) Start range of slice
|
|
|
|
|
• {finish} (number) End range of slice
|
2021-03-11 08:11:11 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
(list) Copy of table sliced from start to finish (inclusive)
|
2021-03-11 08:11:11 -07:00
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
pesc({s}) *vim.pesc()*
|
2022-08-08 09:58:32 -07:00
|
|
|
|
Escapes magic chars in |lua-patterns|.
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {s} (string) String to escape
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(string) %-escaped pattern string
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
https://github.com/rxi/lume
|
|
|
|
|
|
2021-09-25 19:08:36 -07:00
|
|
|
|
split({s}, {sep}, {kwargs}) *vim.split()*
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Splits a string at each instance of a separator.
|
|
|
|
|
|
|
|
|
|
Examples: >
|
2021-09-25 19:08:36 -07:00
|
|
|
|
|
2022-10-09 09:19:43 -07:00
|
|
|
|
split(":aa::b:", ":") => {'','aa','','b',''}
|
|
|
|
|
split("axaby", "ab?") => {'','x','y'}
|
|
|
|
|
split("x*yz*o", "*", {plain=true}) => {'x','yz','o'}
|
|
|
|
|
split("|x|y|z|", "|", {trimempty=true}) => {'x', 'y', 'z'}
|
2019-11-17 20:06:59 -07:00
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {s} (string) String to split
|
|
|
|
|
• {sep} (string) Separator or pattern
|
2022-10-24 05:53:53 -07:00
|
|
|
|
• {kwargs} ({plain: boolean, trimempty: boolean}|nil) Keyword
|
|
|
|
|
arguments:
|
2021-09-25 19:08:36 -07:00
|
|
|
|
• plain: (boolean) If `true` use `sep` literally (passed to
|
|
|
|
|
string.find)
|
|
|
|
|
• trimempty: (boolean) If `true` remove empty items from the
|
|
|
|
|
front and back of the list
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-27 13:44:01 -07:00
|
|
|
|
string[] List of split components
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-10-24 05:53:53 -07:00
|
|
|
|
See also: ~
|
|
|
|
|
|vim.gsplit()|
|
|
|
|
|
|
2020-01-13 00:41:55 -07:00
|
|
|
|
startswith({s}, {prefix}) *vim.startswith()*
|
2022-03-13 05:48:14 -07:00
|
|
|
|
Tests if `s` starts with `prefix`.
|
2020-01-13 00:41:55 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {s} (string) String
|
|
|
|
|
• {prefix} (string) Prefix to match
|
2020-01-13 00:41:55 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if `prefix` is a prefix of `s`
|
2020-01-13 00:41:55 -07:00
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
tbl_add_reverse_lookup({o}) *vim.tbl_add_reverse_lookup()*
|
|
|
|
|
Add the reverse lookup values to an existing table. For example:
|
2022-05-11 09:23:46 -07:00
|
|
|
|
`tbl_add_reverse_lookup { A = 1 } == { [1] = 'A', A = 1 }`
|
|
|
|
|
|
|
|
|
|
Note that this modifies the input.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {o} (table) Table to add the reverse to
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(table) o
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
tbl_contains({t}, {value}) *vim.tbl_contains()*
|
2022-03-13 05:48:14 -07:00
|
|
|
|
Checks if a list-like (vector) table contains `value`.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table to check
|
|
|
|
|
• {value} any Value to compare
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if `t` contains `value`
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2020-07-02 04:09:17 -07:00
|
|
|
|
tbl_count({t}) *vim.tbl_count()*
|
2022-03-13 05:48:14 -07:00
|
|
|
|
Counts the number of non-nil values in table `t`.
|
2020-07-02 04:09:17 -07:00
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
vim.tbl_count({ a=1, b=2 }) => 2
|
|
|
|
|
vim.tbl_count({ 1, 2 }) => 2
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(number) Number of non-nil values in table
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
https://github.com/Tieske/Penlight/blob/master/lua/pl/tablex.lua
|
|
|
|
|
|
|
|
|
|
tbl_deep_extend({behavior}, {...}) *vim.tbl_deep_extend()*
|
|
|
|
|
Merges recursively two or more map-like tables.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {behavior} (string) Decides what to do if a key is found in more than
|
2022-05-12 07:02:46 -07:00
|
|
|
|
one map:
|
2020-07-02 04:09:17 -07:00
|
|
|
|
• "error": raise an error
|
|
|
|
|
• "keep": use value from the leftmost map
|
|
|
|
|
• "force": use value from the rightmost map
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {...} (table) Two or more map-like tables
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
(table) Merged table
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
2022-09-25 16:58:27 -07:00
|
|
|
|
|vim.tbl_extend()|
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
tbl_extend({behavior}, {...}) *vim.tbl_extend()*
|
|
|
|
|
Merges two or more map-like tables.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {behavior} (string) Decides what to do if a key is found in more than
|
2022-05-12 07:02:46 -07:00
|
|
|
|
one map:
|
2019-11-17 20:06:59 -07:00
|
|
|
|
• "error": raise an error
|
|
|
|
|
• "keep": use value from the leftmost map
|
|
|
|
|
• "force": use value from the rightmost map
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {...} (table) Two or more map-like tables
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(table) Merged table
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|extend()|
|
|
|
|
|
|
2020-07-02 04:09:17 -07:00
|
|
|
|
tbl_filter({func}, {t}) *vim.tbl_filter()*
|
|
|
|
|
Filter a table using a predicate function
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
• {func} (function) Function
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
(table) Table of filtered values
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
tbl_flatten({t}) *vim.tbl_flatten()*
|
|
|
|
|
Creates a copy of a list-like table such that any nested tables are
|
|
|
|
|
"unrolled" and appended to the result.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) List-like table
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(table) Flattened copy of the given list-like table
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
2021-10-19 12:55:22 -07:00
|
|
|
|
From https://github.com/premake/premake-core/blob/master/src/base/table.lua
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2022-03-24 12:01:04 -07:00
|
|
|
|
tbl_get({o}, {...}) *vim.tbl_get()*
|
|
|
|
|
Index into a table (first argument) via string keys passed as subsequent
|
2022-05-11 09:23:46 -07:00
|
|
|
|
arguments. Return `nil` if the key does not exist.
|
|
|
|
|
|
|
|
|
|
Examples: >
|
2022-03-24 12:01:04 -07:00
|
|
|
|
|
|
|
|
|
vim.tbl_get({ key = { nested_key = true }}, 'key', 'nested_key') == true
|
|
|
|
|
vim.tbl_get({ key = {}}, 'key', 'nested_key') == nil
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {o} (table) Table to index
|
|
|
|
|
• {...} (string) Optional strings (0 or more, variadic) via which to
|
2022-05-11 09:23:46 -07:00
|
|
|
|
index the table
|
2022-03-24 12:01:04 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-11 09:23:46 -07:00
|
|
|
|
any Nested value indexed by key (if it exists), else nil
|
2022-03-24 12:01:04 -07:00
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
tbl_isempty({t}) *vim.tbl_isempty()*
|
2020-08-31 00:51:35 -07:00
|
|
|
|
Checks if a table is empty.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table to check
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if `t` is empty
|
2020-08-31 00:51:35 -07:00
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
See also: ~
|
2020-08-31 00:51:35 -07:00
|
|
|
|
https://github.com/premake/premake-core/blob/master/src/base/table.lua
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
tbl_islist({t}) *vim.tbl_islist()*
|
2020-09-06 16:55:49 -07:00
|
|
|
|
Tests if a Lua table can be treated as an array.
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
2020-09-06 16:55:49 -07:00
|
|
|
|
Empty table `{}` is assumed to be an array, unless it was created by
|
|
|
|
|
|vim.empty_dict()| or returned as a dict-like |API| or Vimscript result,
|
|
|
|
|
for example from |rpcrequest()| or |vim.fn|.
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(boolean) `true` if array-like table, else `false`
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
tbl_keys({t}) *vim.tbl_keys()*
|
|
|
|
|
Return a list of all keys used in a table. However, the order of the
|
|
|
|
|
return table of keys is not guaranteed.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
(list) List of keys
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
2021-10-19 12:55:22 -07:00
|
|
|
|
From https://github.com/premake/premake-core/blob/master/src/base/table.lua
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
2020-07-02 04:09:17 -07:00
|
|
|
|
tbl_map({func}, {t}) *vim.tbl_map()*
|
|
|
|
|
Apply a function to all values of a table.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
• {func} (function) Function
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table
|
2022-05-11 09:23:46 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(table) Table of transformed values
|
2020-07-02 04:09:17 -07:00
|
|
|
|
|
2019-12-28 04:27:25 -07:00
|
|
|
|
tbl_values({t}) *vim.tbl_values()*
|
|
|
|
|
Return a list of all values used in a table. However, the order of the
|
|
|
|
|
return table of values is not guaranteed.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {t} (table) Table
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-09-28 04:22:08 -07:00
|
|
|
|
(list) List of values
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
trim({s}) *vim.trim()*
|
|
|
|
|
Trim whitespace (Lua pattern "%s") from both sides of a string.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {s} (string) String to trim
|
2019-12-28 04:27:25 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(string) String with whitespace removed from its beginning and end
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
See also: ~
|
2019-12-28 04:27:25 -07:00
|
|
|
|
https://www.lua.org/pil/20.2.html
|
2019-11-17 20:06:59 -07:00
|
|
|
|
|
|
|
|
|
validate({opt}) *vim.validate()*
|
|
|
|
|
Validates a parameter specification (types and values).
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Usage example: >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
function user.new(name, age, hobbies)
|
|
|
|
|
vim.validate{
|
|
|
|
|
name={name, 'string'},
|
|
|
|
|
age={age, 'number'},
|
|
|
|
|
hobbies={hobbies, 'table'},
|
|
|
|
|
}
|
|
|
|
|
...
|
|
|
|
|
end
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Examples with explicit argument values (can be run directly): >
|
|
|
|
|
|
|
|
|
|
vim.validate{arg1={{'foo'}, 'table'}, arg2={'foo', 'string'}}
|
|
|
|
|
=> NOP (success)
|
2021-11-28 04:33:44 -07:00
|
|
|
|
|
|
|
|
|
vim.validate{arg1={1, 'table'}}
|
|
|
|
|
=> error('arg1: expected table, got number')
|
|
|
|
|
|
|
|
|
|
vim.validate{arg1={3, function(a) return (a % 2) == 0 end, 'even number'}}
|
|
|
|
|
=> error('arg1: expected even number, got 3')
|
2019-11-17 20:06:59 -07:00
|
|
|
|
<
|
|
|
|
|
|
2022-01-01 12:35:15 -07:00
|
|
|
|
If multiple types are valid they can be given as a list. >
|
|
|
|
|
|
|
|
|
|
vim.validate{arg1={{'foo'}, {'table', 'string'}}, arg2={'foo', {'table', 'string'}}}
|
|
|
|
|
=> NOP (success)
|
|
|
|
|
|
|
|
|
|
vim.validate{arg1={1, {'string', table'}}}
|
|
|
|
|
=> error('arg1: expected string|table, got number')
|
|
|
|
|
<
|
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {opt} (table) Names of parameters to validate. Each key is a
|
2022-05-12 07:02:46 -07:00
|
|
|
|
parameter name; each value is a tuple in one of these forms:
|
2019-11-17 20:06:59 -07:00
|
|
|
|
1. (arg_value, type_name, optional)
|
|
|
|
|
• arg_value: argument value
|
2022-01-01 12:35:15 -07:00
|
|
|
|
• type_name: string|table type name, one of: ("table", "t",
|
|
|
|
|
"string", "s", "number", "n", "boolean", "b", "function",
|
|
|
|
|
"f", "nil", "thread", "userdata") or list of them.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
• optional: (optional) boolean, if true, `nil` is valid
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2019-11-17 20:06:59 -07:00
|
|
|
|
2. (arg_value, fn, msg)
|
|
|
|
|
• arg_value: argument value
|
|
|
|
|
• fn: any function accepting one argument, returns true if
|
|
|
|
|
and only if the argument is valid. Can optionally return
|
2020-10-20 12:57:07 -07:00
|
|
|
|
an additional informative error message as the second
|
|
|
|
|
returned value.
|
2019-11-17 20:06:59 -07:00
|
|
|
|
• msg: (optional) error string if validation fails
|
|
|
|
|
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: uri *lua-uri*
|
|
|
|
|
|
|
|
|
|
uri_from_bufnr({bufnr}) *vim.uri_from_bufnr()*
|
|
|
|
|
Get a URI from a bufnr
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {bufnr} (number)
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(string) URI
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
uri_from_fname({path}) *vim.uri_from_fname()*
|
|
|
|
|
Get a URI from a file path.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {path} (string) Path to file
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(string) URI
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
uri_to_bufnr({uri}) *vim.uri_to_bufnr()*
|
2021-11-18 13:12:21 -07:00
|
|
|
|
Get the buffer for a uri. Creates a new unloaded buffer if no buffer for
|
|
|
|
|
the uri already exists.
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {uri} (string)
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(number) bufnr
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
uri_to_fname({uri}) *vim.uri_to_fname()*
|
|
|
|
|
Get a filename from a URI
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {uri} (string)
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
2022-05-12 07:02:46 -07:00
|
|
|
|
(string) filename or unchanged URI for non-file URIs
|
2020-09-14 06:12:17 -07:00
|
|
|
|
|
2021-09-27 12:57:28 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: ui *lua-ui*
|
|
|
|
|
|
2021-11-07 08:13:53 -07:00
|
|
|
|
input({opts}, {on_confirm}) *vim.ui.input()*
|
|
|
|
|
Prompts the user for input
|
|
|
|
|
|
2022-02-13 06:44:51 -07:00
|
|
|
|
Example: >
|
|
|
|
|
|
|
|
|
|
vim.ui.input({ prompt = 'Enter value for shiftwidth: ' }, function(input)
|
|
|
|
|
vim.o.shiftwidth = tonumber(input)
|
|
|
|
|
end)
|
|
|
|
|
<
|
|
|
|
|
|
2021-11-07 08:13:53 -07:00
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {opts} (table) Additional options. See |input()|
|
2022-06-28 02:53:15 -07:00
|
|
|
|
• prompt (string|nil) Text of the prompt
|
2021-11-07 08:13:53 -07:00
|
|
|
|
• default (string|nil) Default reply to the input
|
|
|
|
|
• completion (string|nil) Specifies type of completion
|
|
|
|
|
supported for input. Supported types are the same that
|
|
|
|
|
can be supplied to a user-defined command using the
|
|
|
|
|
"-complete=" argument. See |:command-completion|
|
|
|
|
|
• highlight (function) Function that will be used for
|
|
|
|
|
highlighting user inputs.
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {on_confirm} (function) ((input|nil) -> ()) Called once the user
|
2022-05-12 07:02:46 -07:00
|
|
|
|
confirms or abort the input. `input` is what the user
|
2022-11-07 17:15:15 -07:00
|
|
|
|
typed (it might be an empty string if nothing was
|
|
|
|
|
entered), or `nil` if the user aborted the dialog.
|
2021-11-07 08:13:53 -07:00
|
|
|
|
|
2021-09-27 12:57:28 -07:00
|
|
|
|
select({items}, {opts}, {on_choice}) *vim.ui.select()*
|
|
|
|
|
Prompts the user to pick a single item from a collection of entries
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-02-13 06:44:51 -07:00
|
|
|
|
Example: >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-02-13 06:44:51 -07:00
|
|
|
|
vim.ui.select({ 'tabs', 'spaces' }, {
|
|
|
|
|
prompt = 'Select tabs or spaces:',
|
|
|
|
|
format_item = function(item)
|
|
|
|
|
return "I'd like to choose " .. item
|
|
|
|
|
end,
|
|
|
|
|
}, function(choice)
|
|
|
|
|
if choice == 'spaces' then
|
|
|
|
|
vim.o.expandtab = true
|
|
|
|
|
else
|
|
|
|
|
vim.o.expandtab = false
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
<
|
|
|
|
|
|
2021-09-27 12:57:28 -07:00
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {items} (table) Arbitrary items
|
|
|
|
|
• {opts} (table) Additional options
|
2021-09-27 12:57:28 -07:00
|
|
|
|
• prompt (string|nil) Text of the prompt. Defaults to
|
|
|
|
|
`Select one of:`
|
|
|
|
|
• format_item (function item -> text) Function to format
|
|
|
|
|
an individual item from `items`. Defaults to
|
2022-03-13 05:48:14 -07:00
|
|
|
|
`tostring`.
|
2021-11-18 14:50:55 -07:00
|
|
|
|
• kind (string|nil) Arbitrary hint string indicating the
|
|
|
|
|
item shape. Plugins reimplementing `vim.ui.select` may
|
|
|
|
|
wish to use this to infer the structure or semantics of
|
2022-03-13 05:48:14 -07:00
|
|
|
|
`items`, or the context in which select() was called.
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {on_choice} (function) ((item|nil, idx|nil) -> ()) Called once the
|
2021-09-27 12:57:28 -07:00
|
|
|
|
user made a choice. `idx` is the 1-based index of `item`
|
|
|
|
|
within `items`. `nil` if the user aborted the dialog.
|
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: filetype *lua-filetype*
|
|
|
|
|
|
|
|
|
|
add({filetypes}) *vim.filetype.add()*
|
|
|
|
|
Add new filetype mappings.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
Filetype mappings can be added either by extension or by filename (either
|
|
|
|
|
the "tail" or the full file path). The full file path is checked first,
|
|
|
|
|
followed by the file name. If a match is not found using the filename,
|
2022-04-21 12:46:07 -07:00
|
|
|
|
then the filename is matched against the list of |lua-patterns| (sorted by
|
|
|
|
|
priority) until a match is found. Lastly, if pattern matching does not
|
|
|
|
|
find a filetype, then the file extension is used.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
The filetype can be either a string (in which case it is used as the
|
|
|
|
|
filetype directly) or a function. If a function, it takes the full path
|
|
|
|
|
and buffer number of the file as arguments (along with captures from the
|
|
|
|
|
matched pattern, if any) and should return a string that will be used as
|
2022-06-09 12:12:36 -07:00
|
|
|
|
the buffer's filetype. Optionally, the function can return a second
|
|
|
|
|
function value which, when called, modifies the state of the buffer. This
|
|
|
|
|
can be used to, for example, set filetype-specific buffer variables.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
Filename patterns can specify an optional priority to resolve cases when a
|
|
|
|
|
file path matches multiple patterns. Higher priorities are matched first.
|
2022-09-21 14:58:57 -07:00
|
|
|
|
When omitted, the priority defaults to 0. A pattern can contain
|
|
|
|
|
environment variables of the form "${SOME_VAR}" that will be automatically
|
|
|
|
|
expanded. If the environment variable is not set, the pattern won't be
|
|
|
|
|
matched.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
See $VIMRUNTIME/lua/vim/filetype.lua for more examples.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
Example: >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
vim.filetype.add({
|
|
|
|
|
extension = {
|
2022-07-19 08:12:10 -07:00
|
|
|
|
foo = 'fooscript',
|
2022-01-04 07:28:29 -07:00
|
|
|
|
bar = function(path, bufnr)
|
|
|
|
|
if some_condition() then
|
2022-07-19 08:12:10 -07:00
|
|
|
|
return 'barscript', function(bufnr)
|
2022-06-09 12:12:36 -07:00
|
|
|
|
-- Set a buffer variable
|
|
|
|
|
vim.b[bufnr].barscript_version = 2
|
2022-08-11 05:25:48 -07:00
|
|
|
|
end
|
2022-06-09 12:12:36 -07:00
|
|
|
|
end
|
2022-07-19 08:12:10 -07:00
|
|
|
|
return 'bar'
|
2022-01-04 07:28:29 -07:00
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
filename = {
|
2022-07-19 08:12:10 -07:00
|
|
|
|
['.foorc'] = 'toml',
|
|
|
|
|
['/etc/foo/config'] = 'toml',
|
2022-01-04 07:28:29 -07:00
|
|
|
|
},
|
|
|
|
|
pattern = {
|
2022-07-19 08:12:10 -07:00
|
|
|
|
['.*/etc/foo/.*'] = 'fooscript',
|
2022-01-04 07:28:29 -07:00
|
|
|
|
-- Using an optional priority
|
2022-07-19 08:12:10 -07:00
|
|
|
|
['.*/etc/foo/.*%.conf'] = { 'dosini', { priority = 10 } },
|
2022-09-21 14:58:57 -07:00
|
|
|
|
-- A pattern containing an environment variable
|
|
|
|
|
['${XDG_CONFIG_HOME}/foo/git'] = 'git',
|
2022-07-19 08:12:10 -07:00
|
|
|
|
['README.(a+)$'] = function(path, bufnr, ext)
|
|
|
|
|
if ext == 'md' then
|
|
|
|
|
return 'markdown'
|
|
|
|
|
elseif ext == 'rst' then
|
|
|
|
|
return 'rst'
|
2022-01-04 07:28:29 -07:00
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
<
|
|
|
|
|
|
2022-10-16 23:52:40 -07:00
|
|
|
|
To add a fallback match on contents, use >
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-07-03 06:31:56 -07:00
|
|
|
|
vim.filetype.add {
|
|
|
|
|
pattern = {
|
|
|
|
|
['.*'] = {
|
|
|
|
|
priority = -math.huge,
|
|
|
|
|
function(path, bufnr)
|
|
|
|
|
local content = vim.filetype.getlines(bufnr, 1)
|
2022-08-01 05:45:43 -07:00
|
|
|
|
if vim.filetype.matchregex(content, [[^#!.*\<mine\>]]) then
|
2022-07-03 06:31:56 -07:00
|
|
|
|
return 'mine'
|
2022-08-01 05:45:43 -07:00
|
|
|
|
elseif vim.filetype.matchregex(content, [[\<drawing\>]]) then
|
2022-07-03 06:31:56 -07:00
|
|
|
|
return 'drawing'
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
<
|
|
|
|
|
|
2022-01-04 07:28:29 -07:00
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {filetypes} (table) A table containing new filetype maps (see
|
2022-01-04 07:28:29 -07:00
|
|
|
|
example).
|
|
|
|
|
|
2022-07-03 06:31:56 -07:00
|
|
|
|
match({args}) *vim.filetype.match()*
|
2022-06-26 09:41:20 -07:00
|
|
|
|
Perform filetype detection.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-06-26 09:41:20 -07:00
|
|
|
|
The filetype can be detected using one of three methods:
|
|
|
|
|
1. Using an existing buffer
|
|
|
|
|
2. Using only a file name
|
|
|
|
|
3. Using only file contents
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-06-26 09:41:20 -07:00
|
|
|
|
Of these, option 1 provides the most accurate result as it uses both the
|
|
|
|
|
buffer's filename and (optionally) the buffer contents. Options 2 and 3
|
|
|
|
|
can be used without an existing buffer, but may not always provide a match
|
|
|
|
|
in cases where the filename (or contents) cannot unambiguously determine
|
|
|
|
|
the filetype.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-06-26 09:41:20 -07:00
|
|
|
|
Each of the three options is specified using a key to the single argument
|
|
|
|
|
of this function. Example:
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
-- Using a buffer number
|
|
|
|
|
vim.filetype.match({ buf = 42 })
|
|
|
|
|
|
2022-06-27 01:03:43 -07:00
|
|
|
|
-- Override the filename of the given buffer
|
|
|
|
|
vim.filetype.match({ buf = 42, filename = 'foo.c' })
|
|
|
|
|
|
|
|
|
|
-- Using a filename without a buffer
|
|
|
|
|
vim.filetype.match({ filename = 'main.lua' })
|
2022-06-26 09:41:20 -07:00
|
|
|
|
|
|
|
|
|
-- Using file contents
|
2022-06-27 01:03:43 -07:00
|
|
|
|
vim.filetype.match({ contents = {'#!/usr/bin/env bash'} })
|
2022-06-26 09:41:20 -07:00
|
|
|
|
<
|
2022-01-17 11:28:23 -07:00
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {args} (table) Table specifying which matching strategy to use.
|
2022-07-03 06:31:56 -07:00
|
|
|
|
Accepted keys are:
|
|
|
|
|
• buf (number): Buffer number to use for matching. Mutually
|
|
|
|
|
exclusive with {contents}
|
|
|
|
|
• filename (string): Filename to use for matching. When {buf}
|
|
|
|
|
is given, defaults to the filename of the given buffer
|
|
|
|
|
number. The file need not actually exist in the filesystem.
|
|
|
|
|
When used without {buf} only the name of the file is used
|
|
|
|
|
for filetype matching. This may result in failure to detect
|
|
|
|
|
the filetype in cases where the filename alone is not enough
|
|
|
|
|
to disambiguate the filetype.
|
|
|
|
|
• contents (table): An array of lines representing file
|
|
|
|
|
contents to use for matching. Can be used with {filename}.
|
|
|
|
|
Mutually exclusive with {buf}.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-06-09 12:12:36 -07:00
|
|
|
|
Return: ~
|
|
|
|
|
(string|nil) If a match was found, the matched filetype.
|
|
|
|
|
(function|nil) A function that modifies buffer state when called (for
|
|
|
|
|
example, to set some filetype specific buffer variables). The function
|
|
|
|
|
accepts a buffer number as its only argument.
|
|
|
|
|
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: keymap *lua-keymap*
|
|
|
|
|
|
|
|
|
|
del({modes}, {lhs}, {opts}) *vim.keymap.del()*
|
|
|
|
|
Remove an existing mapping. Examples: >
|
|
|
|
|
|
|
|
|
|
vim.keymap.del('n', 'lhs')
|
|
|
|
|
|
|
|
|
|
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', { buffer = 5 })
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {opts} (table|nil) A table of optional arguments:
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
|
• buffer: (number or boolean) Remove a mapping from the given
|
|
|
|
|
buffer. When "true" or 0, use the current buffer.
|
|
|
|
|
|
|
|
|
|
See also: ~
|
|
|
|
|
|vim.keymap.set()|
|
|
|
|
|
|
|
|
|
|
set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*
|
|
|
|
|
Add a new |mapping|. Examples: >
|
|
|
|
|
|
|
|
|
|
-- Can add mapping to Lua functions
|
|
|
|
|
vim.keymap.set('n', 'lhs', function() print("real lua function") end)
|
|
|
|
|
|
|
|
|
|
-- Can use it to map multiple modes
|
|
|
|
|
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, { buffer=true })
|
|
|
|
|
|
|
|
|
|
-- Can add mapping for specific buffer
|
|
|
|
|
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", { silent = true, buffer = 5 })
|
|
|
|
|
|
|
|
|
|
-- Expr mappings
|
|
|
|
|
vim.keymap.set('i', '<Tab>', function()
|
|
|
|
|
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
|
|
|
|
|
end, { expr = true })
|
|
|
|
|
-- <Plug> mappings
|
|
|
|
|
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Note that in a mapping like: >
|
|
|
|
|
|
|
|
|
|
vim.keymap.set('n', 'asdf', require('jkl').my_fun)
|
|
|
|
|
<
|
|
|
|
|
|
2022-03-20 11:00:30 -07:00
|
|
|
|
the `require('jkl')` gets evaluated during this call in order to access the function. If you
|
2022-03-13 05:48:14 -07:00
|
|
|
|
want to avoid this cost at startup you can wrap it in a function, for
|
|
|
|
|
example: >
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
|
|
|
|
|
|
vim.keymap.set('n', 'asdf', function() return require('jkl').my_fun() end)
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {mode} string|table Same mode short names as |nvim_set_keymap()|. Can
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
|
also be list of modes to create mapping on multiple modes.
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {lhs} (string) Left-hand side |{lhs}| of the mapping.
|
|
|
|
|
• {rhs} string|function Right-hand side |{rhs}| of the mapping. Can
|
2022-08-01 20:13:22 -07:00
|
|
|
|
also be a Lua function.
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {opts} (table|nil) A table of |:map-arguments|.
|
2022-08-13 15:38:31 -07:00
|
|
|
|
• Accepts options accepted by the {opts} parameter in
|
|
|
|
|
|nvim_set_keymap()|, with the following notable differences:
|
|
|
|
|
• replace_keycodes: Defaults to `true` if "expr" is `true`.
|
|
|
|
|
• noremap: Always overridden with the inverse of "remap"
|
|
|
|
|
(see below).
|
|
|
|
|
|
|
|
|
|
• In addition to those options, the table accepts the
|
|
|
|
|
following keys:
|
|
|
|
|
• buffer: (number or boolean) Add a mapping to the given
|
|
|
|
|
buffer. When `0` or `true`, use the current buffer.
|
|
|
|
|
• remap: (boolean) Make the mapping recursive. This is the
|
|
|
|
|
inverse of the "noremap" option from |nvim_set_keymap()|.
|
|
|
|
|
Defaults to `false`.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
feat(lua): add vim.keymap
This introduces two new functions `vim.keymap.set` & `vim.keymap.del`
differences compared to regular set_keymap:
- remap is used as opposite of noremap. By default it's true for <Plug> keymaps and false for others.
- rhs can be lua function.
- mode can be a list of modes.
- replace_keycodes option for lua function expr maps. (Default: true)
- handles buffer specific keymaps
Examples:
```lua
vim.keymap.set('n', 'asdf', function() print("real lua function") end)
vim.keymap.set({'n', 'v'}, '<leader>lr', vim.lsp.buf.references, {buffer=true})
vim.keymap.set('n', '<leader>w', "<cmd>w<cr>", {silent = true, buffer = 5 })
vim.keymap.set('i', '<Tab>', function()
return vim.fn.pumvisible() == 1 and "<C-n>" or "<Tab>"
end, {expr = true})
vim.keymap.set('n', '[%', '<Plug>(MatchitNormalMultiBackward)')
vim.keymap.del('n', 'asdf')
vim.keymap.del({'n', 'i', 'v'}, '<leader>w', {buffer = 5 })
```
2021-12-30 00:30:49 -07:00
|
|
|
|
See also: ~
|
|
|
|
|
|nvim_set_keymap()|
|
|
|
|
|
|
2022-05-15 13:38:19 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: fs *lua-fs*
|
|
|
|
|
|
2022-05-15 18:55:18 -07:00
|
|
|
|
basename({file}) *vim.fs.basename()*
|
|
|
|
|
Return the basename of the given file or directory
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {file} (string) File or directory
|
2022-05-15 18:55:18 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(string) Basename of {file}
|
|
|
|
|
|
2022-05-15 19:10:12 -07:00
|
|
|
|
dir({path}) *vim.fs.dir()*
|
|
|
|
|
Return an iterator over the files and directories located in {path}
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {path} (string) An absolute or relative path to the directory to
|
2022-05-17 07:49:33 -07:00
|
|
|
|
iterate over. The path is first normalized
|
|
|
|
|
|vim.fs.normalize()|.
|
2022-05-15 19:10:12 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
Iterator over files and directories in {path}. Each iteration yields
|
|
|
|
|
two values: name and type. Each "name" is the basename of the file or
|
|
|
|
|
directory relative to {path}. Type is one of "file" or "directory".
|
|
|
|
|
|
2022-05-15 18:53:23 -07:00
|
|
|
|
dirname({file}) *vim.fs.dirname()*
|
|
|
|
|
Return the parent directory of the given file or directory
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {file} (string) File or directory
|
2022-05-15 18:53:23 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(string) Parent directory of {file}
|
|
|
|
|
|
2022-05-15 19:37:35 -07:00
|
|
|
|
find({names}, {opts}) *vim.fs.find()*
|
|
|
|
|
Find files or directories in the given path.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-15 19:37:35 -07:00
|
|
|
|
Finds any files or directories given in {names} starting from {path}. If
|
|
|
|
|
{upward} is "true" then the search traverses upward through parent
|
|
|
|
|
directories; otherwise, the search traverses downward. Note that downward
|
|
|
|
|
searches are recursive and may search through many directories! If {stop}
|
|
|
|
|
is non-nil, then the search stops when the directory given in {stop} is
|
|
|
|
|
reached. The search terminates when {limit} (default 1) matches are found.
|
2022-11-25 16:52:30 -07:00
|
|
|
|
The search can be narrowed to find only files or only directories by
|
2022-05-15 19:37:35 -07:00
|
|
|
|
specifying {type} to be "file" or "directory", respectively.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-15 19:37:35 -07:00
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {names} (string|table|fun(name: string): boolean) Names of the files
|
2022-09-13 13:16:20 -07:00
|
|
|
|
and directories to find. Must be base names, paths and globs
|
2022-11-23 16:40:07 -07:00
|
|
|
|
are not supported. The function is called per file and
|
|
|
|
|
directory within the traversed directories to test if they
|
|
|
|
|
match {names}.
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {opts} (table) Optional keyword arguments:
|
2022-05-15 19:37:35 -07:00
|
|
|
|
• path (string): Path to begin searching from. If omitted,
|
2022-11-23 16:40:07 -07:00
|
|
|
|
the |current-directory| is used.
|
2022-05-15 19:37:35 -07:00
|
|
|
|
• upward (boolean, default false): If true, search upward
|
|
|
|
|
through parent directories. Otherwise, search through child
|
|
|
|
|
directories (recursively).
|
|
|
|
|
• stop (string): Stop searching when this directory is
|
|
|
|
|
reached. The directory itself is not searched.
|
|
|
|
|
• type (string): Find only files ("file") or directories
|
|
|
|
|
("directory"). If omitted, both files and directories that
|
2022-11-23 16:40:07 -07:00
|
|
|
|
match {names} are included.
|
2022-05-15 19:37:35 -07:00
|
|
|
|
• limit (number, default 1): Stop the search after finding
|
|
|
|
|
this many matches. Use `math.huge` to place no limit on the
|
|
|
|
|
number of matches.
|
2022-08-11 05:25:48 -07:00
|
|
|
|
|
2022-05-15 19:37:35 -07:00
|
|
|
|
Return: ~
|
2022-11-23 16:40:07 -07:00
|
|
|
|
(table) The normalized paths |vim.fs.normalize()| of all matching
|
|
|
|
|
files or directories
|
2022-05-15 19:37:35 -07:00
|
|
|
|
|
2022-05-17 07:49:33 -07:00
|
|
|
|
normalize({path}) *vim.fs.normalize()*
|
|
|
|
|
Normalize a path to a standard format. A tilde (~) character at the
|
|
|
|
|
beginning of the path is expanded to the user's home directory and any
|
|
|
|
|
backslash (\) characters are converted to forward slashes (/). Environment
|
|
|
|
|
variables are also expanded.
|
|
|
|
|
|
2022-11-23 16:40:07 -07:00
|
|
|
|
Examples: >
|
2022-05-17 07:49:33 -07:00
|
|
|
|
|
2022-11-23 16:40:07 -07:00
|
|
|
|
vim.fs.normalize('C:\Users\jdoe')
|
|
|
|
|
=> 'C:/Users/jdoe'
|
2022-05-17 07:49:33 -07:00
|
|
|
|
|
2022-11-23 16:40:07 -07:00
|
|
|
|
vim.fs.normalize('~/src/neovim')
|
|
|
|
|
=> '/home/jdoe/src/neovim'
|
2022-05-17 07:49:33 -07:00
|
|
|
|
|
2022-11-23 16:40:07 -07:00
|
|
|
|
vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim')
|
|
|
|
|
=> '/Users/jdoe/.config/nvim/init.vim'
|
2022-05-17 07:49:33 -07:00
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {path} (string) Path to normalize
|
2022-05-17 07:49:33 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(string) Normalized path
|
|
|
|
|
|
2022-05-15 13:38:19 -07:00
|
|
|
|
parents({start}) *vim.fs.parents()*
|
|
|
|
|
Iterate over all the parents of the given file or directory.
|
|
|
|
|
|
|
|
|
|
Example: >
|
|
|
|
|
|
|
|
|
|
local root_dir
|
|
|
|
|
for dir in vim.fs.parents(vim.api.nvim_buf_get_name(0)) do
|
|
|
|
|
if vim.fn.isdirectory(dir .. "/.git") == 1 then
|
|
|
|
|
root_dir = dir
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if root_dir then
|
|
|
|
|
print("Found git repository at", root_dir)
|
|
|
|
|
end
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
2022-10-05 05:15:55 -07:00
|
|
|
|
• {start} (string) Initial file or directory.
|
2022-05-15 13:38:19 -07:00
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(function) Iterator
|
|
|
|
|
|
2022-11-05 12:37:05 -07:00
|
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
|
Lua module: secure *lua-secure*
|
|
|
|
|
|
|
|
|
|
read({path}) *vim.secure.read()*
|
|
|
|
|
Attempt to read the file at {path} prompting the user if the file should
|
|
|
|
|
be trusted. The user's choice is persisted in a trust database at
|
|
|
|
|
$XDG_STATE_HOME/nvim/trust.
|
|
|
|
|
|
|
|
|
|
Parameters: ~
|
|
|
|
|
• {path} (string) Path to a file to read.
|
|
|
|
|
|
|
|
|
|
Return: ~
|
|
|
|
|
(string|nil) The contents of the given file if it exists and is
|
|
|
|
|
trusted, or nil otherwise.
|
|
|
|
|
|
2020-09-06 16:55:49 -07:00
|
|
|
|
vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:
|