Plugins and modules included with Nvim
Rustvim :help pages, generated
from source
using the tree-sitter-vimdoc parser.
Nvim includes various Lua and Vim plugins or modules which may provide
commands (such as :TOhtml) or modules that you can optionally require() or
:packadd. The Lua ones are not part of the lua-stdlib, that is, they are not
available from the global
vim module namespace. Some of the plugins are
loaded by default while others are not loaded until requested by :packadd.
Standard plugins
| Help-link | Loaded | Short description |
|---|---|---|
| dir | Yes | Directory listing for :edit |
| difftool | No | Compares directories (and files) side-by-side |
| editorconfig | Yes | Detect and interpret editorconfig |
| ft-shada | Yes | Allows editing binary shada files |
| man.lua | Yes | View manpages in Nvim |
| |matchit| | Yes | Extended % matching |
| matchparen | Yes | Highlight matching pairs |
| netrw | No | Reading and writing files over a network |
| zip | Yes | Read-only zip archive browser |
| package-cfilter | No | Filtering quickfix/location list |
| package-justify | No | Justify text |
| package-nohlsearch | No | Automatically run :nohlsearch |
| package-spellfile | Yes | Install spellfile if missing |
| package-termdebug | No | Debug inside Nvim with gdb |
| package-tohtml | No | Convert buffer to html, syntax included |
| package-undotree | No | Interactive textual undotree |
| pi_gzip.txt | Yes | Reading and writing compressed files |
| pi_msgpack.txt | No | msgpack utilities |
| pi_paren.txt | Yes | Highlight matching parens |
| pi_spec.txt | Yes | Filetype plugin to work with rpm spec files |
| pi_swapmouse | No | Swap meaning of left and right mouse buttons |
| pi_tar.txt | Yes | Tar file explorer |
| pi_tutor.txt | Yes | Interactive tutorial |
| old-zip | No | Legacy zip archive explorer |
Builtin plugin: dir
Nvim opens a directory listing when you :edit a directory path, handled by
the builtin "dir" plugin. The listing is read-only, dir.lua does not provide
actions which modify the filesystem.
Each "dir" buffer is initialized as follows:
Sets 'filetype' to "directory".
Keeps alternate-file, so CTRL-^ returns to the buffer you came from.
To disable the built-in directory browser, set this before startup:
vim.g.loaded_nvim_dir_plugin = 1
MAPPINGS
<CR> opens the file or directory under the cursor.
a opens the file or directory under the cursor in a vertical split.
o opens the file or directory under the cursor in a horizontal split.
- opens the parent directory.
{count}- is like -, but a count of 1 opens the global working directory,
and a higher count goes up that many levels.
R reloads the directory listing.
a and o are available for local directories and keep focus in the listing.
'splitright' and 'splitbelow' control where the new window appears.
These keys map to
<Plug>(nvim-dir-open), <Plug>(nvim-dir-vsplit),
<Plug>(nvim-dir-split), <Plug>(nvim-dir-up), and <Plug>(nvim-dir-reload); map those
to use different keys. Default mappings are skipped when the target <Plug>
mapping is already mapped. The default "-", "a", and "o" mappings are also
skipped when their keys are already mapped.
To make "-" open the parent directory from any buffer:
vim.keymap.set('n', '-', '<Plug>(nvim-dir-up)')
Directory buffers follow the global 'hidden' option by default. To delete them
after use:
autocmd FileType directory setlocal bufhidden=delete
A discarded listing is rebuilt on the next visit, so the cursor starts at the
first entry instead of the one it was left on. "wipe" discards the buffer
itself, leaving no alternate-file; see 'bufhidden'.
Reshaping the listingdir-render
A User autocommand fired after each listing is rendered, including reloads.
The buffer is writable for the duration, so a handler can sort or filter it
with ordinary commands, and the cursor is placed afterwards.
Handlers may reorder or remove lines, but each remaining line must still be an
entry name: dir-mappings resolve the line under the cursor against the
buffer name, so rewriting line text makes
<CR> open a nonexistent path.
Sort directories last:
autocmd User DirReadPost silent keeppatterns sort r /\/$/
Hide dot-prefixed entries:
autocmd User DirReadPost silent keeppatterns g/^\./d _
Sort by modification time, newest first:
vim.api.nvim_create_autocmd('User', {
pattern = 'DirReadPost',
callback = function(args)
local dir = vim.api.nvim_buf_get_name(args.buf)
local names = vim.api.nvim_buf_get_lines(args.buf, 0, -1, true)
local mtime = {} --- @type table<string, integer>
for _, name in ipairs(names) do
local stat = vim.uv.fs_stat(vim.fs.joinpath(dir, name))
mtime[name] = stat and stat.mtime.sec or 0
end
table.sort(names, function(a, b)
return mtime[a] > mtime[b]
end)
vim.api.nvim_buf_set_lines(args.buf, 0, -1, true, names)
end,
})
Decorating the listingdir-decorate
A nvim_set_decoration_provider() sets extmarks on the visible lines of
each redraw, so they survive reordering by a DirReadPost handler.
Classify each entry, and show where a symbolic link points:
local ns = vim.api.nvim_create_namespace('my.dir.classify')
local glyph = {
fifo = '|', socket = '=', char = '%', block = '#',
}
vim.api.nvim_set_decoration_provider(ns, {
on_win = function(_, _, buf)
return vim.bo[buf].filetype == 'directory'
end,
on_range = function(_, _, buf, row)
local dir = vim.api.nvim_buf_get_name(buf)
local name = vim.api.nvim_buf_get_lines(buf, row, row + 1, true)[1]
local path = vim.fs.joinpath(dir, (name:gsub('/$', '')))
local stat = vim.uv.fs_lstat(path) or {}
local exe = stat.type == 'file'
and bit.band(stat.mode, tonumber('111', 8)) ~= 0
local char = glyph[stat.type] or (exe and '*')
if char then
vim.api.nvim_buf_set_extmark(buf, ns, row, #name, {
virt_text = { { char, 'Dimmed' } },
virt_text_pos = 'overlay',
ephemeral = true,
})
end
if stat.type == 'link' then
local target = vim.uv.fs_readlink(path) or '?'
vim.api.nvim_buf_set_extmark(buf, ns, row, 0, {
virt_text = { { '-> ' .. target, 'Dimmed' } },
virt_text_pos = 'eol',
ephemeral = true,
})
end
return row + 1
end,
})
Replacing the directory browserdir-disable
To use another directory browser for the current session, delete the
nvim.dir autocommand group on or after VimEnter and handle FileType "directory".
This clears the built-in directory-opening autocommands.
vim.api.nvim_del_augroup_by_name('nvim.dir')
vim.api.nvim_create_autocmd('FileType', {
pattern = 'directory',
callback = function(args)
require('my_browser').open(args.buf, vim.api.nvim_buf_get_name(args.buf))
end,
})
To enable the legacy "netrw" plugin:
:packadd netrw
The plugin and its mappings remain loaded (it is a core component used by
other features such as zip).
Builtin plugin: difftool
Compares two directories or files side-by-side.
Supports directory diffing, rename detection, and highlights changes
in quickfix list. Replaces the built-in
nvim -d diff mode with this interface.
The plugin is not loaded by default; use
:packadd to activate it::packadd nvim.difftool
Example
git difftool -d integration using nvim -d replacement:[difftool "nvim_difftool"]
cmd = nvim -c \"packadd nvim.difftool\" -d \"$LOCAL\" \"$REMOTE\"
[diff]
tool = nvim_difftool
Diff two files or directories
Parameters:
{left} (string)
{right} (string)
{opt} (table?)
{rename.detect} (boolean, default: false) Whether to
detect renames
{rename.similarity} (number, default: 0.5) Minimum
similarity for rename detection (0 to 1)
{rename.chunk_size} (number, default: 4096) Maximum
chunk size to read from files for similarity calculation
{ignore} (string[], default: {}) List of file patterns
to ignore (for example: '.git', '*.log')
{method} ('auto'|'builtin'|'diffr', default: auto) Diff
method to use
{rename} (table) Controls rename detection
Builtin plugin: editorconfig
EditorConfig is like 'modeline' for an entire (recursive) directory. When a
file is opened, after running ftplugins and FileType autocommands, the
EditorConfig feature searches all parent directories of that file for
.editorconfig files, parses them, and applies their properties. For more
information see https://editorconfig.org/.
Example
.editorconfig file:root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
max_line_length = 42
trim_trailing_whitespace = true
[*.{diff,md}]
trim_trailing_whitespace = false
EditorConfig is enabled by default. To disable it, add to your config:
vim.g.editorconfig = false
(Vimscript:
let g:editorconfig = v:false). It can also be disabled
per-buffer by setting the b:editorconfig buffer-local variable to false.
Nvim stores the applied properties in b:editorconfig if it is not
false.
New properties can be added by adding a new entry to the "properties" table.
The table key is a property name and the value is a callback function which
accepts the number of the buffer to be modified, the value of the property in
the
.editorconfig file, and (optionally) a table containing all of the other
properties and their values (useful for properties which depend on other
properties). The value is always a string and must be coerced if necessary.
Example:
require('editorconfig').properties.foo = function(bufnr, val, opts)
if opts.charset and opts.charset ~= "utf-8" then
error("foo can only be set when charset is utf-8", 0)
end
vim.b[bufnr].foo = val
end
The following properties are supported by default:
charseteditorconfig.charset
One of "utf-8", "utf-8-bom", "latin1", "utf-16be", or
"utf-16le". Sets the 'fileencoding' and 'bomb' options.
end_of_lineeditorconfig.end_of_line
One of "lf", "crlf", or "cr". These correspond to setting
'fileformat' to "unix", "dos", or "mac", respectively.
indent_sizeeditorconfig.indent_size
A number indicating the size of a single indent. Alternatively, use the
value "tab" to use the value of the tab_width property. Sets the
'shiftwidth' and 'softtabstop' options. If this value is not "tab" and the
tab_width property is not set, 'tabstop' is also set to this value.
insert_final_newlineeditorconfig.insert_final_newline
"true" or "false" to ensure the file always has a trailing newline as
its last byte. Sets the 'fixendofline' and 'endofline' options.
max_line_lengtheditorconfig.max_line_length
A number indicating the maximum length of a single line. Sets the
'textwidth' option.
If "true", then stop searching for
.editorconfig files in parent
directories. This property must be at the top-level of the .editorconfig
file (i.e. it must not be within a glob section). It only controls the
search and is excluded from property callbacks and b:editorconfig.
spelling_languageeditorconfig.spelling_language
A code of the format ss or ss-TT, where ss is an ISO 639 language code and
TT is an ISO 3166 territory identifier. Sets the 'spelllang' option.
tab_widtheditorconfig.tab_width
The display size of a single tab character. Sets the 'tabstop' option.
trim_trailing_whitespaceeditorconfig.trim_trailing_whitespace
When "true", trailing whitespace is automatically removed when the
buffer is written.
Builtin plugin: spellfile
Asks the user to download missing spellfiles. The spellfile is written to
stdpath('data') .. 'site/spell' or the first writable directory in the
'runtimepath'.
The plugin can be disabled by setting
g:loaded_spellfile_plugin = 1.
nvim.spellfile.Confignvim.spellfile.Config
A table with the following fields:
Fields:
{confirm} (boolean, default: true) Whether to ask user to
confirm download.
{timeout_ms} (integer, default: 15000) Number of milliseconds after
which the vim.net.request() times out.
{url} (string) The base URL from where the spellfiles are
downloaded. Uses g:spellfile_URL if it's set,
otherwise https://ftp.nluug.nl/pub/vim/runtime/spell.
config(
Configure spellfile download options. Omit {opts})spellfile.config(){opts} to retrieve the current
configuration. Otherwise, update only the supplied fields.
For example:
require('nvim.spellfile').config({ url = '...' })
Parameters:
{opts} (Partial<nvim.spellfile.Config>?)
Return:
(nvim.spellfile.Config?) Current config if {opts} is omitted.
get(
Download spellfiles for language {lang})spellfile.get(){lang} if available.
Parameters:
{lang} (string) Language code.
Return:
(table?) A table with the following fields:
{dir} (string)
{encoding} (string)
{files} (string[])
{key} (string)
{lang} (string)
Builtin plugin: tohtml
:[range]TOhtml
Converts the buffer shown in the current window to HTML, opens the generated
HTML in a new split window, and saves its contents to {file}:TOhtml{file}. If {file} is not
given, a temporary file (created by tempname()) is used.
The plugin is not loaded by default; use
:packadd to activate it::packadd nvim.tohtml
Converts the buffer shown in the window
{winid} to HTML and returns the
output as a list of string.
Parameters:
{winid} (integer?) Window to convert (defaults to current window)
{opt} (table?) Optional parameters.
{font}? (string[]|string, default: guifont) Fonts to
use.
{number_lines}? (boolean, default: false) Show line
numbers.
{range}? (integer[], default: entire buffer) Range of
rows to use.
{title}? (string|false, default: buffer name) Title tag
to set in the generated HTML code.
{width}? (integer, default: 'textwidth' if non-zero or
window width otherwise) Width used for items which are
either right aligned or repeat a character infinitely.
Return:
(string[])
Builtin plugin: undotree
open(
Open a window that displays a textual representation of the undo-tree,
or closes the window if it is already open. Can also be shown with
{opts})undotree.open():Undotree.:Undotree
While in the window, moving the cursor changes the undo.
The plugin is not loaded by default; use
:packadd to activate it::packadd nvim.undotree
Parameters:
{opts} (table?) A table with the following fields:
{bufnr} (integer?) Buffer to draw the tree into. If
omitted, a new buffer is created.
{command} (string?) Vimscript command to create the
window. Default value is "30vnew". Only used when {winid} is
nil.
{title} ((string|fun(bufnr:integer):string?)?) Title of
the window. If a function, it accepts the buffer number of
the source buffer as its only argument and should return a
string.
{winid} (integer?) Window id to display the tree buffer
in. If omitted, a new window is created with {command}.
Return:
(boolean?) Returns true if the window was already open, nil
otherwise