Home Explore Blog CI



neovim

8th chunk of `runtime/doc/repeat.txt`
be3249c6f2b95a0bcc90e6f0e83b340d89fdd4f5d542e7d80000000100000fa8

- contain multiple plugins that depend on each other.
- contain plugins that are automatically loaded on startup ("start" packages,
  located in "pack/*/start/*") and ones that are only loaded when needed with
  |:packadd| ("opt" packages, located in "pack/*/opt/*").

							*runtime-search-path*
Nvim searches for |:runtime| files in:
	1. all paths in 'runtimepath'
	2. all "pack/*/start/*" dirs

Note that the "pack/*/start/*" paths are not explicitly included in
'runtimepath', so they will not be reported by ":set rtp" or "echo &rtp".
Scripts can use |nvim_list_runtime_paths()| to list all used directories, and
|nvim_get_runtime_file()| to query for specific files or sub-folders within
the runtime path. Example: >
	" List all runtime dirs and packages with Lua paths.
	:echo nvim_get_runtime_file("lua/", v:true)

Using a package and loading automatically ~

Let's assume your Nvim files are in "~/.local/share/nvim/site" and you want to
add a package from a zip archive "/tmp/foopack.zip": >
	% mkdir -p ~/.local/share/nvim/site/pack/foo
	% cd ~/.local/share/nvim/site/pack/foo
	% unzip /tmp/foopack.zip

The directory name "foo" is arbitrary, you can pick anything you like.

You would now have these files under ~/.local/share/nvim/site:
	pack/foo/README.txt
	pack/foo/start/foobar/plugin/foo.vim
	pack/foo/start/foobar/syntax/some.vim
	pack/foo/opt/foodebug/plugin/debugger.vim

On startup after processing your |config|, Nvim scans all directories in
'packpath' for plugins in "pack/*/start/*", then loads the plugins.

To allow for calling into package functionality while parsing your |vimrc|,
|:colorscheme| and |autoload| will both automatically search under 'packpath'
as well in addition to 'runtimepath'.  See the documentation for each for
details.

In the example Nvim will find "pack/foo/start/foobar/plugin/foo.vim" and load
it.

If the "foobar" plugin kicks in and sets the 'filetype' to "some", Nvim will
find the syntax/some.vim file, because its directory is in the runtime search
path.

Nvim will also load ftdetect files, if there are any.

Note that the files under "pack/foo/opt" are not loaded automatically, only the
ones under "pack/foo/start".  See |pack-add| below for how the "opt" directory
is used.

Loading packages automatically will not happen if loading plugins is disabled,
see |load-plugins|.

To load packages earlier, so that plugin/ files are sourced:
	:packloadall
This also works when loading plugins is disabled.  The automatic loading will
only happen once.

If the package has an "after" directory, that directory is added to the end of
'runtimepath', so that anything there will be loaded later.


Using a single plugin and loading it automatically ~

If you don't have a package but a single plugin, you need to create the extra
directory level: >
	% mkdir -p ~/.local/share/nvim/site/pack/foo/start/foobar
	% cd ~/.local/share/nvim/site/pack/foo/start/foobar
	% unzip /tmp/someplugin.zip

You would now have these files:
	pack/foo/start/foobar/plugin/foo.vim
	pack/foo/start/foobar/syntax/some.vim

From here it works like above.


Optional plugins ~
							*pack-add*
To load an optional plugin from a pack use the `:packadd` command: >
	:packadd foodebug
This searches for "pack/*/opt/foodebug" in 'packpath' and will find
~/.local/share/nvim/site/pack/foo/opt/foodebug/plugin/debugger.vim and source
it.

This could be done if some conditions are met.  For example, depending on
whether Nvim supports a feature or a dependency is missing.

You can also load an optional plugin at startup, by putting this command in
your |config|: >
	:packadd! foodebug
The extra "!" is so that the plugin isn't loaded if Nvim was started with
|--noplugin|.

It is perfectly normal for a package to only have files in the "opt"
directory.  You then need to load each plugin when you want to use it.


Where to put what ~

Since color schemes, loaded with `:colorscheme`, are found below
"pack/*/start" and "pack/*/opt", you could put them anywhere.  We recommend

Title: Package Loading and Structure
Summary
This section explains how Neovim searches for runtime files in 'runtimepath' and 'pack/*/start/*' directories, and how to load packages automatically by placing them in the 'pack/*/start/*' directory. It details the directory structure required for single plugins and how to load optional plugins using the `:packadd` command. It also provides guidance on where to place different types of files within the package structure.