aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/health.vim2
-rw-r--r--runtime/autoload/health/provider.vim2
-rw-r--r--runtime/doc/api.txt253
-rw-r--r--runtime/doc/lua.txt16
-rw-r--r--runtime/doc/message.txt2
-rw-r--r--runtime/ftplugin/cpp.vim1
-rw-r--r--runtime/lua/vim/filetype.lua2
-rw-r--r--runtime/lua/vim/shared.lua27
8 files changed, 212 insertions, 93 deletions
diff --git a/runtime/autoload/health.vim b/runtime/autoload/health.vim
index ec030adf04..1292e4344e 100644
--- a/runtime/autoload/health.vim
+++ b/runtime/autoload/health.vim
@@ -188,7 +188,7 @@ function! s:get_healthcheck_list(plugin_names) abort
\ + nvim_get_runtime_file('lua/**/'.p.'/health/init.lua', v:true)
\ + nvim_get_runtime_file('lua/**/'.p.'/health.lua', v:true)
if len(paths) == 0
- let healthchecks += [[p, '', '']] " healthchek not found
+ let healthchecks += [[p, '', '']] " healthcheck not found
else
let healthchecks += map(uniq(sort(paths)),
\'<SID>filepath_to_healthcheck(v:val)')
diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim
index 6022e05c22..a01cb9631c 100644
--- a/runtime/autoload/health/provider.vim
+++ b/runtime/autoload/health/provider.vim
@@ -690,7 +690,7 @@ function! s:check_perl() abort
if empty(perl_exec)
if !empty(perl_warnings)
call health#report_warn(perl_warnings, ['See :help provider-perl for more information.',
- \ 'You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim'])
+ \ 'You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim'])
else
call health#report_warn('No usable perl executable found')
endif
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index fa2f8f974a..02a27e15f8 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -452,7 +452,7 @@ Extended marks (extmarks) represent buffer annotations that track text changes
in the buffer. They can represent cursors, folds, misspelled words, anything
that needs to track a logical location in the buffer over time. |api-indexing|
-Extmark position works like "bar" cursor: it exists between characters. Thus
+Extmark position works like "bar" cursor: it exists between characters. Thus,
the maximum extmark index on a line is 1 more than the character index: >
f o o b a r line contents
@@ -468,7 +468,7 @@ extmark position and enter some text, the extmark migrates forward. >
f o o z|b a r line (| = cursor)
4 extmark (after typing "z")
-If an extmark is on the last index of a line and you inputs a newline at that
+If an extmark is on the last index of a line and you input a newline at that
point, the extmark will accordingly migrate to the next line: >
f o o z b a r| line (| = cursor)
@@ -3152,129 +3152,204 @@ nvim_tabpage_set_var({tabpage}, {name}, {value})
Autocmd Functions *api-autocmd*
nvim_create_augroup({name}, {*opts}) *nvim_create_augroup()*
- Create or get an augroup.
+ Create or get an autocommand group |autocmd-groups|.
- To get an existing augroup ID, do: >
- local id = vim.api.nvim_create_augroup(name, {
+ To get an existing group id, do: >
+ local id = vim.api.nvim_create_augroup("MyGroup", {
clear = false
})
<
Parameters: ~
- {name} String: The name of the augroup to create
- {opts} Parameters
- • clear (bool): Whether to clear existing commands
- or not. Defaults to true. See |autocmd-groups|
+ {name} String: The name of the group
+ {opts} Dictionary Parameters
+ • clear (bool) optional: defaults to true. Clear
+ existing commands if the group already exists
+ |autocmd-groups|.
Return: ~
- opaque value to use with nvim_del_augroup_by_id
+ Integer id of the created group.
+
+ See also: ~
+ |autocmd-groups|
nvim_create_autocmd({event}, {*opts}) *nvim_create_autocmd()*
- Create an autocmd.
+ Create an |autocommand|
- Examples:
- • event: "pat1,pat2,pat3",
- • event: "pat1"
- • event: { "pat1" }
- • event: { "pat1", "pat2", "pat3" }
+ The API allows for two (mutually exclusive) types of actions
+ to be executed when the autocommand triggers: a callback
+ function (Lua or Vimscript), or a command (like regular
+ autocommands).
- Parameters: ~
- {event} The event or events to register this autocmd
- Required keys: event: string | ArrayOf(string)
+ Example using callback: >
+ -- Lua function
+ local myluafun = function() print("This buffer enters") end
- Parameters: ~
- {opts} Optional Parameters:
- • callback: (string|function)
- • (string): The name of the viml function to
- execute when triggering this autocmd
- • (function): The lua function to execute when
- triggering this autocmd
- • NOTE: Cannot be used with {command}
+ -- Vimscript function name (as a string)
+ local myvimfun = "g:MyVimFunction"
- • command: (string) command
- • vimscript command
- • NOTE: Cannot be used with {callback} Eg.
- command = "let g:value_set = v:true"
+ vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
+ pattern = {"*.c", "*.h"},
+ callback = myluafun, -- Or myvimfun
+ })
+<
+
+ Example using command: >
+ vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
+ pattern = {"*.c", "*.h"},
+ command = "echo 'Entering a C or C++ file'",
+ })
+<
- • pattern: (string|table)
- • pattern or patterns to match against
- • defaults to "*".
- • NOTE: Cannot be used with {buffer}
+ Example values for pattern: >
+ pattern = "*.py"
+ pattern = { "*.py", "*.pyi" }
+<
- • buffer: (bufnr)
- • create a |autocmd-buflocal| autocmd.
- • NOTE: Cannot be used with {pattern}
+ Examples values for event: >
+ "BufPreWrite"
+ {"CursorHold", "BufPreWrite", "BufPostWrite"}
+<
- • group: (string|int) The augroup name or id
- • once: (boolean) - See |autocmd-once|
- • nested: (boolean) - See |autocmd-nested|
- • desc: (string) - Description of the autocmd
+ Parameters: ~
+ {event} (String|Array) The event or events to register
+ this autocommand
+ {opts} Dictionary of autocommand options:
+ • group (string|integer) optional: the
+ autocommand group name or id to match against.
+ • pattern (string|array) optional: pattern or
+ patterns to match against |autocmd-pattern|.
+ • buffer (integer) optional: buffer number for
+ buffer local autocommands |autocmd-buflocal|.
+ Cannot be used with {pattern}.
+ • desc (string) optional: description of the
+ autocommand.
+ • callback (function|string) optional: Lua
+ function or Vim function (as string) to execute
+ on event. Cannot be used with {command}
+ • command (string) optional: Vim command to
+ execute on event. Cannot be used with
+ {callback}
+ • once (boolean) optional: defaults to false. Run
+ the autocommand only once |autocmd-once|.
+ • nested (boolean) optional: defaults to false.
+ Run nested autocommands |autocmd-nested|.
+
+ Return: ~
+ Integer id of the created autocommand.
- Return: ~
- opaque value to use with nvim_del_autocmd
+ See also: ~
+ |autocommand|
+ |nvim_del_autocmd()|
nvim_del_augroup_by_id({id}) *nvim_del_augroup_by_id()*
- Delete an augroup by {id}. {id} can only be returned when
- augroup was created with |nvim_create_augroup|.
+ Delete an autocommand group by id.
- NOTE: behavior differs from augroup-delete.
+ To get a group id one can use |nvim_get_autocmds()|.
- When deleting an augroup, autocmds contained by this augroup
- will also be deleted and cleared. This augroup will no longer
- exist
+ NOTE: behavior differs from |augroup-delete|. When deleting a
+ group, autocommands contained in this group will also be
+ deleted and cleared. This group will no longer exist.
-nvim_del_augroup_by_name({name}) *nvim_del_augroup_by_name()*
- Delete an augroup by {name}.
+ Parameters: ~
+ {id} Integer The id of the group.
- NOTE: behavior differs from augroup-delete.
+ See also: ~
+ |nvim_del_augroup_by_name()|
+ |nvim_create_augroup()|
- When deleting an augroup, autocmds contained by this augroup
- will also be deleted and cleared. This augroup will no longer
- exist
+nvim_del_augroup_by_name({name}) *nvim_del_augroup_by_name()*
+ Delete an autocommand group by name.
-nvim_del_autocmd({id}) *nvim_del_autocmd()*
- Delete an autocmd by {id}. Autocmds only return IDs when
- created via the API. Will not error if called and no autocmds
- match the {id}.
+ NOTE: behavior differs from |augroup-delete|. When deleting a
+ group, autocommands contained in this group will also be
+ deleted and cleared. This group will no longer exist.
Parameters: ~
- {id} Integer The ID returned by nvim_create_autocmd
+ {name} String The name of the group.
-nvim_do_autocmd({event}, {*opts}) *nvim_do_autocmd()*
- Do one autocmd.
+ See also: ~
+ |autocommand-groups|
+
+nvim_del_autocmd({id}) *nvim_del_autocmd()*
+ Delete an autocommand by id.
+
+ NOTE: Only autocommands created via the API have an id.
Parameters: ~
- {event} The event or events to execute
- {opts} Optional Parameters:
- • buffer (number) - buffer number
- • NOTE: Cannot be used with {pattern}
+ {id} Integer The id returned by nvim_create_autocmd
- • pattern (string|table) - optional, defaults to
- "*".
- • NOTE: Cannot be used with {buffer}
+ See also: ~
+ |nvim_create_autocmd()|
- • group (string|int) - autocmd group name or id
- • modeline (boolean) - Default true, see
- |<nomodeline>|
+nvim_do_autocmd({event}, {*opts}) *nvim_do_autocmd()*
+ Execute an autocommand |autocmd-execute|.
+
+ Parameters: ~
+ {event} (String|Array) The event or events to execute
+ {opts} Dictionary of autocommand options:
+ • group (string|integer) optional: the
+ autocommand group name or id to match against.
+ |autocmd-groups|.
+ • pattern (string|array) optional: defaults to
+ "*" |autocmd-pattern|. Cannot be used with
+ {buffer}.
+ • buffer (integer) optional: buffer number
+ |autocmd-buflocal|. Cannot be used with
+ {pattern}.
+ • modeline (bool) optional: defaults to true.
+ Process the modeline after the autocommands
+ |<nomodeline>|.
-nvim_get_autocmds({*opts}) *nvim_get_autocmds()*
- Get autocmds that match the requirements passed to {opts}.
+ See also: ~
+ |:doautocmd|
- Parameters: ~
- {opts} Optional Parameters:
- • event : Name or list of name of events to match
- against
- • group (string|int): Name or id of group to match
- against
- • pattern: Pattern or list of patterns to match
- against. Cannot be used with {buffer}
- • buffer: Buffer number or list of buffer numbers
- for buffer local autocommands
- |autocmd-buflocal|. Cannot be used with
- {pattern}
+nvim_get_autocmds({*opts}) *nvim_get_autocmds()*
+ Get autocommands that match the requirements passed to {opts}.
+
+ These examples will get autocommands matching ALL the given
+ criteria: >
+ -- Matches all criteria
+ autocommands = vim.api.nvim_get_autocmds({
+ group = "MyGroup",
+ event = {"BufEnter", "BufWinEnter"},
+ pattern = {"*.c", "*.h"}
+ })
+
+ -- All commands from one group
+ autocommands = vim.api.nvim_get_autocmds({
+ group = "MyGroup",
+ })
+<
- Return: ~
- A list of autocmds that match
+ NOTE: When multiple patterns or events are provided, it will
+ find all the autocommands that match any combination of them.
+
+ Parameters: ~
+ {opts} Dictionary with at least one of the following:
+ • group (string|integer): the autocommand group
+ name or id to match against.
+ • event (string|array): event or events to match
+ against |autocmd-events|.
+ • pattern (string|array): pattern or patterns to
+ match against |autocmd-pattern|.
+
+ Return: ~
+ Array of autocommands matching the criteria, with each
+ item containing the following fields:
+ • id (number): the autocommand id (only when defined with
+ the API).
+ • group (integer): the autocommand group id.
+ • desc (string): the autocommand description.
+ • event (string): the autocommand event.
+ • command (string): the autocommand command.
+ • once (boolean): whether the autocommand is only run
+ once.
+ • pattern (string): the autocommand pattern. If the
+ autocommand is buffer local |autocmd-buffer-local|:
+ • buflocal (boolean): true if the autocommand is buffer
+ local.
+ • buffer (number): the buffer number.
==============================================================================
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index bd821c4f9e..21f44ce02e 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -1634,6 +1634,22 @@ tbl_flatten({t}) *vim.tbl_flatten()*
See also: ~
From https://github.com/premake/premake-core/blob/master/src/base/table.lua
+tbl_get({o}, {...}) *vim.tbl_get()*
+ Index into a table (first argument) via string keys passed as
+ subsequent arguments. Return `nil` if the key does not exist. Examples: >
+
+ vim.tbl_get({ key = { nested_key = true }}, 'key', 'nested_key') == true
+ vim.tbl_get({ key = {}}, 'key', 'nested_key') == nil
+<
+
+ Parameters: ~
+ {o} Table to index
+ {...} Optional strings (0 or more, variadic) via which to
+ index the table
+
+ Return: ~
+ nested value indexed by key if it exists, else nil
+
tbl_isempty({t}) *vim.tbl_isempty()*
Checks if a table is empty.
diff --git a/runtime/doc/message.txt b/runtime/doc/message.txt
index fa1bc6f7da..dac4df5ee9 100644
--- a/runtime/doc/message.txt
+++ b/runtime/doc/message.txt
@@ -61,7 +61,7 @@ If you are lazy, it also works without the shift key: >
When an error message is displayed, but it is removed before you could read
it, you can see it again with: >
- :echo errmsg
+ :echo v:errmsg
Or view a list of recent messages with: >
:messages
See `:messages` above.
diff --git a/runtime/ftplugin/cpp.vim b/runtime/ftplugin/cpp.vim
index f9d31cbec3..58c4e4b24a 100644
--- a/runtime/ftplugin/cpp.vim
+++ b/runtime/ftplugin/cpp.vim
@@ -10,6 +10,7 @@ endif
" Behaves mostly just like C
runtime! ftplugin/c.vim ftplugin/c_*.vim ftplugin/c/*.vim
+runtime! ftplugin/c.lua ftplugin/c_*.lua ftplugin/c/*.lua
" C++ uses templates with <things>
" Disabled, because it gives an error for typing an unmatched ">".
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index b356f5e3dc..ab71de54f8 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -21,7 +21,7 @@ end
---@private
local function getline(bufnr, lnum)
- return api.nvim_buf_get_lines(bufnr, lnum-1, lnum, false)[1]
+ return api.nvim_buf_get_lines(bufnr, lnum-1, lnum, false)[1] or ""
end
-- Filetypes based on file extension
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 3eb332279a..f0dc34608c 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -347,6 +347,33 @@ function vim.tbl_add_reverse_lookup(o)
return o
end
+--- Index into a table (first argument) via string keys passed as subsequent arguments.
+--- Return `nil` if the key does not exist.
+--_
+--- Examples:
+--- <pre>
+--- vim.tbl_get({ key = { nested_key = true }}, 'key', 'nested_key') == true
+--- vim.tbl_get({ key = {}}, 'key', 'nested_key') == nil
+--- </pre>
+---
+---@param o Table to index
+---@param ... Optional strings (0 or more, variadic) via which to index the table
+---
+---@returns nested value indexed by key if it exists, else nil
+function vim.tbl_get(o, ...)
+ local keys = {...}
+ if #keys == 0 then
+ return
+ end
+ for _, k in ipairs(keys) do
+ o = o[k]
+ if o == nil then
+ return
+ end
+ end
+ return o
+end
+
--- Extends a list-like table with the values of another list-like table.
---
--- NOTE: This mutates dst!