Nvim :help pages, generated
from source
using the tree-sitter-vimdoc parser.
" List all runtime dirs and packages with Lua paths.
:echo nvim_get_runtime_file("lua/", v:true)
% mkdir -p ~/.local/share/nvim/site/pack/foo % cd ~/.local/share/nvim/site/pack/foo % unzip /tmp/foopack.zipThe directory name "foo" is arbitrary, you can pick anything you like.
pack/foo/README.txt pack/foo/start/foobar/plugin/foo.vim pack/foo/start/foobar/syntax/some.vim pack/foo/opt/foodebug/plugin/debugger.vimOn startup after processing your config, Nvim scans all directories in 'packpath' for plugins in "pack/*/start/*", then loads the plugins.
% mkdir -p ~/.local/share/nvim/site/pack/foo/start/foobar % cd ~/.local/share/nvim/site/pack/foo/start/foobar % unzip /tmp/someplugin.zipYou would now have these files:
pack/foo/start/foobar/plugin/foo.vim pack/foo/start/foobar/syntax/some.vimFrom here it works like above.
:packadd command::packadd foodebugThis searches for "pack/*/opt/foodebug" in 'packpath' and will find ~/.local/share/nvim/site/pack/foo/opt/foodebug/plugin/debugger.vim and source it.
:packadd! foodebugThe extra "!" is so that the plugin isn't loaded if Nvim was started with --noplugin.
:colorscheme, are found below
"pack/*/start" and "pack/*/opt", you could put them anywhere. We recommend
you put them below "pack/*/opt", for example
"~/.config/nvim/pack/mycolors/opt/dark/colors/very_dark.vim".
:packadd. E.g. depending on the compiler
version:if foo_compiler_version > 34 packadd foo_new else packadd foo_old endifThe "after" directory is most likely not useful in a package. It's not disallowed though.
:packadd.
start/foobar/plugin/foo.vim " always loaded, defines commands start/foobar/plugin/bar.vim " always loaded, defines commands start/foobar/autoload/foo.vim " loaded when foo command used start/foobar/doc/foo.txt " help for foo.vim start/foobar/doc/tags " help tags opt/fooextra/plugin/extra.vim " optional plugin, defines commands opt/fooextra/autoload/extra.vim " loaded when extra command used opt/fooextra/doc/extra.txt " help for extra.vim opt/fooextra/doc/tags " help tags
mkdir ~/.local/share/nvim/site/pack cd ~/.local/share/nvim/site/pack git clone https://github.com/you/foobar.git myfoobarHere "myfoobar" is a name that the user can choose, the only condition is that it differs from other packages.
:packadd! fooextraYou could add this packadd command in one of your plugins, to be executed when the optional plugin is needed.
:helptags command to generate the doc/tags file. Including this
generated file in the package means that the user can drop the package in the
pack directory and the help command works right away. Don't forget to re-run
the command after changing the plugin help::helptags path/start/foobar/doc :helptags path/opt/fooextra/doc
call foolib#getit()pack/foo/start/two/plugin/two.vim
call foolib#getit()pack/foo/start/lib/autoload/foolib.vim
func foolib#getit()This works, because start packages will be searched for autoload files, when sourcing the plugins.
$XDG_DATA_HOME/nvim/site/pack/core/opt. $XDG_DATA_HOME/nvim/site needs to
be part of 'packpath'. It usually is, but might not be in cases like --clean
or setting $XDG_DATA_HOME during startup. Plugin's subdirectory name matches
plugin's name in specification. It is assumed that all plugins in the
directory are managed exclusively by vim.pack.
git executable of at least
version 2.36. Target plugins should be Git repositories with versions as named
tags following semver convention v<major>.<minor>.<patch>.
$XDG_CONFIG_HOME/nvim/nvim-pack-lock.json. It is a JSON file that
is used to persistently track data about plugins. For a more robust config
treat lockfile like its part: put under version control, etc. In this case
initial install prefers revision from the lockfile instead of inferring from
version. Should not be edited by hand or deleted.
vim.pack.add({
-- Install "plugin1" and use default branch (usually `main` or `master`)
'https://github.com/user/plugin1',
-- Same as above, but using a table (allows setting other options)
{ src = 'https://github.com/user/plugin1' },
-- Specify plugin's name (here the plugin will be called "plugin2"
-- instead of "generic-name")
{ src = 'https://github.com/user/generic-name', name = 'plugin2' },
-- Specify version to follow during install and update
{
src = 'https://github.com/user/plugin3',
-- Version constraint, see |vim.version.range()|
version = vim.version.range('1.0'),
},
{
src = 'https://github.com/user/plugin4',
-- Git branch, tag, or commit hash
version = 'main',
},
})
-- Plugin's code can be used directly after `add()`
plugin1 = require('plugin1')add() call. Their revision is
taken from vim.pack-lockfile (if present) or inferred from the version.
version. Let's say, plugin
named 'plugin1' has changed to vim.version.range('*').
version in vim.pack-lockfile is updated.
vim.pack.update({ 'plugin1' }).
version set to current revision. Get
it from vim.pack-lockfile (plugin's field rev; looks like abc12345).
version set to whichever version you
want it to be updated.
active - whether plugin was added via vim.pack.add() to current session.
kind - one of "install" (install on disk; before loading), "update"
(update already installed plugin; might be not loaded), "delete" (delete
from disk).
spec - plugin's specification with defaults made explicit.
path - full path to plugin's directory.
local hooks = function(ev)
-- Use available |event-data|
local name, kind = ev.data.spec.name, ev.data.kind
-- Run build script after plugin's code has changed
if name == 'plug-1' and (kind == 'install' or kind == 'update') then
vim.system({ 'make' }, { cwd = ev.data.path })
end
-- If action relies on code from the plugin (like user command or
-- Lua code), make sure to explicitly load it first
if name == 'plug-2' and kind == 'update' then
if not ev.data.active then
vim.cmd.packadd('plug-2')
end
vim.cmd('PlugTwoUpdate')
require('plug2').after_update()
end
end
-- If hooks need to run on install, run this before `vim.pack.add()`
vim.api.nvim_create_autocmd('PackChanged', { callback = hooks })
{src} (string) URI from which to install and pull updates. Any
format supported by git clone is allowed.
{name}? (string) Name of plugin. Will be used as directory name.
Default: src repository name.
{version}? (string|vim.VersionRange) Version to use for install and
updates. Can be:
nil (no value, default) to use repository's default
branch (usually main or master).
{data}? (any) Arbitrary data associated with a plugin.
{specs}, {opts}) vim.pack.add()src into name
subdirectory (via git clone) and update state to match version
(via git checkout).
load function)
making it reachable by Nvim.
version can be not the one actually
present on disk. Execute vim.pack.update() to synchronize.
{specs} ((string|vim.pack.Spec)[]) List of plugin specifications.
String item is treated as src.
{opts} (table?) A table with the following fields:
{load}?
(boolean|fun(plug_data: {spec: vim.pack.Spec, path: string}))
Load plugin/ files and ftdetect/ scripts. If false,
works like :packadd!. If function, called with plugin
data and is fully responsible for loading plugin. Default
false during startup and true afterwards.
{confirm}? (boolean) Whether to ask user to confirm
initial install. Default true.
{names} (string[]) List of plugin names to remove from disk. Must
be managed by vim.pack, not necessarily already added to
current session.
{opts} (table?) A table with the following fields:
{info} (boolean) Whether to include extra plugin info.
Default true.
table[]) A list of objects with the following fields:
{branches}? (string[]) Available Git branches (first is default).
Missing if info=false.
{path} (string) Plugin's path on disk.
{rev} (string) Current Git revision.
{tags}? (string[]) Available Git tags. Missing if info=false.
{names}, {opts}) vim.pack.update()force:
false, show confirmation buffer. It lists data about all set to
update plugins. Pending changes starting with > will be applied
while the ones starting with < will be reverted. It has dedicated
buffer-local mappings:
gO via lsp-defaults or
vim.lsp.buf.document_symbol()) - show structure of the buffer.
K via lsp-defaults or
vim.lsp.buf.hover()) - show more information at cursor. Like
details of particular pending change or newer tag.
gra via lsp-defaults or
vim.lsp.buf.code_action()) - show code actions available for
"plugin at cursor". Like "delete", "update", or "skip updating".
Execute :write to confirm update, execute :quit to discard the
update.
true, make updates right away.
{names} (string[]?) List of plugin names to update. Must be managed
by vim.pack, not necessarily already added to current
session. Default: names of all plugins managed by vim.pack.
{opts} (table?) A table with the following fields:
{force}? (boolean) Whether to skip confirmation and make
updates immediately. Default false.