Vim 8 package management
How it works
Vim 8 introduced native package management, providing an alternative to popular tools such as Vundle and vim-plug.
The documentation on Vim 8's package management can be accessed via :h packages. It defines a package as a directory that contains one or more plugins. The main highlights of Vim package management are:
- A package can be downloaded as an archive and unpacked in its own directory. Thus the files are not mixed with files of other plugins. That makes it easy to update and remove.
- A package can be a git, mercurial, etc. repository. That makes it really easy to update.
- A package can contain multiple plugins that depend on each other.
- A package can contain plugins that are automatically loaded on start up and ones that are only loaded when needed with :packadd.
To set up package management in Vim, create the following folder:
$ mkdir ~/.vim/pack/<key>
<key> can be anything; a GitHub handle, a username, or a category. For
most cases, a GitHub username should suffice.
<key> directory create another two directories:
start directory holds plugins that are loaded on start up. The
directory holds plugins that can be loaded manually via
Using Git submodules to manage plugins
Packages can contain version controlled repositories. This means if you have a
Git repository version controlling your
.vimrc file and
.vim directory, Git
submodules can be used to manage plugins.
When cloning the Git repository, plugins can be installed by updating the submodules with the following commands:
$ git submodule init $ git submodule update
Installing a plugin
A Git submodule is installed like so:
$ git submodule add https://github.com/editorconfig/editorconfig-vim.git .vim/pack/<key>/start/editorconfig-vim $ git add .vim/pack/<key>/start $ git commit -m "Add EditorConfig Vim plugin"
The folder that the submodule is installed under can be anything but I find it easier to use the repository name as the folder name.
Removing a plugin
There may come a time when a plugin is no longer needed. Removing a plugin means removing the Git submodule:
$ git submodule deinit -f -- .vim/pack/<key>/start/editorconfig-vim $ rm -rf .git/modules/.vim/pack/<key>/start/editorconfig-vim $ git rm -f .vim/pack/<key>/start/editorconfig-vim