The newest and the brightest in plugin management is vim-plug, a lightweight plugin that makes it easy to deal with a multitude of plugins. The plugin is available on GitHub at: https://github.com/junegunn/vim-plug (it has a rather friendly README file, but I've captured the gist of it in this section if you're feeling lazy).
There are some neat things about this plugin:
- It's lightweight and fits in a single file, allowing for some straightforward installation options
- It supports parallel plugin load (if Vim is compiled with Python or Ruby enabled, which is true for all modern Vim setups)
- It supports the lazy loading of most plugins, only invoking plugins for a particular command or a file type
Installing vim-plug is straightforward:
- Fetch the plugin file from https://raw.github.com/junegunn/vim-plug/master/plug.vim.
- Save the file as $HOME/.vim/autoload/plug.vim.
To fetch a single file from GitHub, you can use curl or wget on Linux or macOS, or just open the link in the browser, right-click, and choose Save as.... For instance, you could run the following command to fetch the file in Unix:
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.github.com/junegunn/vim-plug/master/plug.vim - Update your .vimrc file to include vim-plug initializers:
" Manage plugins with vim-plug.
call plug#begin()
call plug#end() - Add some plugins between these two lines, using the last parts of the URL in GitHub (in <username>/<repository> format, for example scrooloose/nerdtree instead of https://github.com/scrooloose/nerdtree) to identify the plugins:
" Manage plugins with vim-plug.
call plug#begin()
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-vinegar'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'mileszs/ack.vim'
Plug 'easymotion/vim-easymotion'
call plug#end() - Save your .vimrc file and reload it (:w | source $MYVIMRC) or restart Vim to apply the changes. Execute :PlugInstall to install the plugins.
This will download the aforementioned plugins from GitHub:
There are two main commands you will use with vim-plug:
- :PlugUpdate will update all of the plugins you have installed.
- :PlugClean will delete the plugins you removed from your .vimrc file. If you don't run :PlugClean, the plugins you deactivated (by either commenting out or removing the relevant Plug ... line in your .vimrc file) will stay on your system.
Lazy plugin loading is a useful tool to prevent plugins from slowing down Vim. The Plug directive supports optional parameters. For instance, if you wanted to load NERDTree when the :NERDTreeToggle command is called, you could use the on parameter:
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
If you wanted to only load a plugin for a particular file type, you could use the for parameter:
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
You can find the list of supported parameters in vim-plug's README file on GitHub at: https://github.com/junegunn/vim-plug.
If you only work on Linux or Mac machines (and Cygwin), you can add a following piece to your .vimrc file to install vim-plug whenever you transport your .vimrc file to a new machine:
" Install vim-plug if it's not already installed.
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
https://raw.github.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
This will install vim-plug (and all the plugins you have listed) next time you open Vim.
You can see a slightly longer solution that works for both Windows and Unix on my blog: https://www.rosipov.com/blog/cross-platform-vim-plug-setup.