Home

Native Vim plugin management

Written on 2020-10-06

For a long time, the best way to manage Vim plugins was to use a third party manager such as Pathogen, Vundle or vim-plug. Vim 8 (and therefore Neovim) has introduced a convenient (enough) way to manage them natively, but only relatively few people use it because:

  1. They don't know about it
  2. They don't know how to use it
  3. They are pleased with their current setup and don't want to change it
While the third reason is valid, I believe that the first two are due to the fact that most of the literature (plugin installation guides, tutorials, etc.) assumes the use of a plugin manager, so let's write some about native plugin management.

Tradeoffs

First of all, let's make clear that the native management method is neither strictly superior or inferior to the use of plugin managers. It's advantages are that it requires no special installation, is more stable and offers more granular control. On the other hand, it doesn't provide a fancy UI or convenient commands to install/update everything at once and generate helptags.

So if you want to cut down on dependencies, avoid downloading random software and have a minimal, stable setup, you might want to try going without an external plugin manager.

How to

Plugins location

Plugins can be put anywhere in the packpath (type :set packpath to print it). By default, it includes ~/.vim/ in Vim, and ~/.config/nvim/ and ~/.local/share/nvim/site/ in Neovim (unless you messed with your XDG environment variables).

Within those paths, the plugins must be put in pack/*/start/ or pack/*/opt/. It doesn't matter what the wildcard matches, so just use plugins or something. Plugins put in start/ are automatically sourced after the user's config whereas the ones in opt/ are optional and therefore only loaded on demand.

Loading plugins

To explicitely load a plugin, simply use packadd plugin-name, where plugin-name is the name of the directory in which the plugin is stored. To load all plugins at once, use packloadall.

To lazy load plugins, simply put them under opt/ and use either an autocommand or ftplugin (i.e. call packadd from some after/ftplugin/*.vim in your runtimepath).

Getting plugins

You can get plugins any way you want, like manually downloading them, git cloning them or using git submodules. For one-time installs, I recommend simply putting them them in ~/.local/share/nvim/site. If you keep your configuration in version control, then I recommend using git submodules in ~/.config/nvim/. In both cases, you can control which version you use for each plugin and don't need to bloat your dotfiles repo.

Generating helptags

Helptags are not automatically generated when plugins are loaded, so you wont have tab completions when looking for documentation for your plugins and won't be able to use tag features in their help files. To generate them for all plugins at once, just use :helptags ALL.