vim._core.util
Methods13
function M.space_above() -> nil
function M.space_below() -> nil
function M.get_buf_by_name(name: string) -> nil | integer
Gets a buffer by name
function M.edit_in(winnr: number, file: string) -> buffer number
Edit a file in a specific window
winnrnumberfilestring
buffernumbernumber of the edited buffer
function M.wrapped_edit(file: string, mods: string | vim.api.keyset.cmd_mods) -> nil
:edit, but it respects commands like :hor, :vert, :tab, etc.
filestringmodsstring | vim.api.keyset.cmd_modsModifier string ("vertical") or structured mods table.
- nil
function M.read_chunk(file: string, size: number) -> chunk nil | string
Read a chunk of data from a file
filestringsizenumber
chunknil | stringor nil on error
function M.source_is_lua(bufnr: integer, line1: integer, line2: integer) -> True boolean
Check if a range in a buffer is inside a Lua codeblock via treesitter injection. Used by :source to detect Lua code in non-Lua files (e.g., vimdoc).
bufnrintegerBuffer number
line1integerStart line (1-indexed)
line2integerEnd line (1-indexed)
Truebooleanif the range is in a Lua injection
function M.term_exitcode() -> string
Returns the exit code string for the current buffer, given:
- Channel is attached to the current buffer
- Current buffer is a terminal buffer
function M.get_forge_url(repo: string, target: string, target_type: "commit" | "tag") -> nil | string
Compute a link to a target on a forge host
repostringURL of repo, usually "https://<domain>/<user>/<name>"
targetstringIdentifier of a target, like commit hash or tag name
target_type"commit" | "tag"
- nil | string
Example: <repo>/releases/tag/<target>
function M.cmd_errmsg(err: string) -> string
Gets a scrubbed message from a pcall'd command error (drops Lua context/traceback): "…/editor.lua:123: Vim(put):E484: xx" => "E484: xx"
function M.echo_err(msg: string) -> nil
Utility function for displaying vim error codes (EXX)
function M.notify(name: string, msg: string, level: nil | integer) -> nil
Shows a message from a builtin plugin, prefixed with the plugin name.
Scheduled, so it is safe to call from |api-fast| contexts.
namestringPlugin name, e.g. "zip".
msgstringlevelnil | integerLevel from |vim.log.levels|. Defaults to ERROR.
- nil
function M.nvim_on(events: vim.api.keyset.events | vim.api.keyset.events[], group: nil | string | integer, opts_or_fn: vim.api.keyset.create_autocmd, fn: fun(ev: vim.api.keyset.create_autocmd.callback_args) -> nil | boolean) -> integer
Define event-handlers (autocmds) ergonomically.
Examples:
local nvim_on = require('vim._core.util').nvim_on
nvim_on('BufWritePost', group, function(ev) print(ev.file) end)
nvim_on({ 'BufRead', 'BufNew' }, group, { pattern = '*.lua' }, function(ev) end)
nvim_on('VimLeavePre', nil, function() end)
function M.nvim_on(events: vim.api.keyset.events | vim.api.keyset.events[], group: nil | string | integer, fn: fun(ev: vim.api.keyset.create_autocmd.callback_args) -> nil | boolean) -> integereventsvim.api.keyset.events | vim.api.keyset.events[]Event(s) to watch. See |autocmd-events|.
groupnil | string | integerGroup name or id, or
nil.opts_or_fnvim.api.keyset.create_autocmdOptions.
fnfun(ev: vim.api.keyset.create_autocmd.callback_args) -> nil | booleanEvent handler.
- integer
Autocmd id (see |nvimcreateautocmd()|).