aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/lua.txt
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc/lua.txt')
-rw-r--r--runtime/doc/lua.txt69
1 files changed, 42 insertions, 27 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 089cf0ce9d..4062a35735 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -704,7 +704,7 @@ regex:match_str({str}) *regex:match_str()*
As any integer is truth-y, `regex:match()` can be directly used
as a condition in an if-statement.
-regex:match_line({bufnr}, {line_idx}[, {start}, {end}]) *regex:match_line()*
+regex:match_line({bufnr}, {line_idx} [, {start}, {end}]) *regex:match_line()*
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
@@ -855,13 +855,13 @@ vim.empty_dict() *vim.empty_dict()*
Note: If numeric keys are present in the table, Nvim ignores the
metatable marker and converts the dict to a list/array anyway.
-vim.rpcnotify({channel}, {method}[, {args}...]) *vim.rpcnotify()*
+vim.rpcnotify({channel}, {method} [, {args}...]) *vim.rpcnotify()*
Sends {event} to {channel} via |RPC| and returns immediately. If
{channel} is 0, the event is broadcast to all channels.
This function also works in a fast callback |lua-loop-callbacks|.
-vim.rpcrequest({channel}, {method}[, {args}...]) *vim.rpcrequest()*
+vim.rpcrequest({channel}, {method} [, {args}...]) *vim.rpcrequest()*
Sends a request to {channel} to invoke {method} via |RPC| and blocks
until a response is received.
@@ -873,7 +873,7 @@ vim.stricmp({a}, {b}) *vim.stricmp()*
are equal, {a} is greater than {b} or {a} is lesser than {b},
respectively.
-vim.str_utfindex({str}[, {index}]) *vim.str_utfindex()*
+vim.str_utfindex({str} [, {index}]) *vim.str_utfindex()*
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.
@@ -883,7 +883,7 @@ vim.str_utfindex({str}[, {index}]) *vim.str_utfindex()*
point each. An {index} in the middle of a UTF-8 sequence is rounded
upwards to the end of that sequence.
-vim.str_byteindex({str}, {index}[, {use_utf16}]) *vim.str_byteindex()*
+vim.str_byteindex({str}, {index} [, {use_utf16}]) *vim.str_byteindex()*
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.
@@ -1291,6 +1291,9 @@ Lua module: vim *lua-vim*
cmd({command}) *vim.cmd()*
Execute Vim script commands.
+ Note that `vim.cmd` can be indexed with a command name to
+ return a callable function to the command.
+
Example: >
vim.cmd('echo 42')
@@ -1300,7 +1303,23 @@ cmd({command}) *vim.cmd()*
autocmd FileType c setlocal cindent
augroup END
]])
- vim.cmd({ cmd = 'echo', args = { '"foo"' } })
+
+ -- 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"')
+
+ -- 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 }
+
+ -- Ex command :colorscheme blue
+ vim.cmd('colorscheme blue')
+ vim.cmd.colorscheme('blue')
<
Parameters: ~
@@ -2029,30 +2048,30 @@ add({filetypes}) *vim.filetype.add()*
vim.filetype.add({
extension = {
- foo = "fooscript",
+ foo = 'fooscript',
bar = function(path, bufnr)
if some_condition() then
- return "barscript", function(bufnr)
+ return 'barscript', function(bufnr)
-- Set a buffer variable
vim.b[bufnr].barscript_version = 2
end
end
- return "bar"
+ return 'bar'
end,
},
filename = {
- [".foorc"] = "toml",
- ["/etc/foo/config"] = "toml",
+ ['.foorc'] = 'toml',
+ ['/etc/foo/config'] = 'toml',
},
pattern = {
- [".*&zwj;/etc/foo/.*"] = "fooscript",
+ ['.*/etc/foo/.*'] = 'fooscript',
-- Using an optional priority
- [".*&zwj;/etc/foo/.*%.conf"] = { "dosini", { priority = 10 } },
- ["README.(%a+)$"] = function(path, bufnr, ext)
- if ext == "md" then
- return "markdown"
- elseif ext == "rst" then
- return "rst"
+ ['.*/etc/foo/.*%.conf'] = { 'dosini', { priority = 10 } },
+ ['README.(a+)$'] = function(path, bufnr, ext)
+ if ext == 'md' then
+ return 'markdown'
+ elseif ext == 'rst' then
+ return 'rst'
end
end,
},
@@ -2068,9 +2087,9 @@ add({filetypes}) *vim.filetype.add()*
priority = -math.huge,
function(path, bufnr)
local content = vim.filetype.getlines(bufnr, 1)
- if vim.filetype.matchregex(content, { [[^#!.*\<mine\>]] }) then
+ if vim.filetype.matchregex(content, [[^#!.*\<mine\>]]) then
return 'mine'
- elseif vim.filetype.matchregex(content, { [[\<drawing\>]] }) then
+ elseif vim.filetype.matchregex(content, [[\<drawing\>]]) then
return 'drawing'
end
end,
@@ -2199,9 +2218,7 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*
create mapping on multiple modes.
{lhs} (string) Left-hand side |{lhs}| of the mapping.
{rhs} string|function Right-hand side |{rhs}| of the
- mapping. Can also be a Lua function. If a Lua
- function and `opts.expr == true`, returning `nil`
- is equivalent to an empty string.
+ mapping. Can also be a Lua function.
{opts} (table) A table of |:map-arguments| such as
"silent". In addition to the options listed in
|nvim_set_keymap()|, this table also accepts the
@@ -2209,13 +2226,11 @@ set({mode}, {lhs}, {rhs}, {opts}) *vim.keymap.set()*
• buffer: (number or boolean) Add a mapping to the
given buffer. When "true" or 0, use the current
buffer.
- • replace_keycodes: (boolean, default true) When
- both this and expr is "true",
- |nvim_replace_termcodes()| is applied to the
- result of Lua expr maps.
• remap: (boolean) Make the mapping recursive.
This is the inverse of the "noremap" option from
|nvim_set_keymap()|. Default `false`.
+ • replace_keycodes: (boolean) defaults to true if
+ "expr" is true.
See also: ~
|nvim_set_keymap()|