Vim-Plug is your go-to for managing Vim plugins, but getting it set up can feel like a maze of commands if you’re not sure where to start.
Let’s get Vim-Plug installed and a plugin working. This is what it looks like when you’re actually adding a plugin.
First, we need to get the plug.vim script. You can do this with curl or wget.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
This command downloads the plug.vim file and places it in the autoload directory within your .vim configuration folder. The --create-dirs flag ensures that the autoload directory is created if it doesn’t exist.
Now, let’s configure Vim to use vim-plug. Open your ~/.vimrc file (or ~/.config/nvim/init.vim for Neovim). If these files don’t exist, create them.
At the very top of your .vimrc (or init.vim), add these lines:
call plug#begin('~/.vim/plugged')
This tells vim-plug where to install your plugins. The path ~/.vim/plugged is the conventional location.
Then, in the middle of your .vimrc, you’ll list the plugins you want. Here’s an example using a popular plugin like vim-fugitive:
" Specify a directory for plugins
" Path can be relative to the home directory or absolute.
call plug#begin('~/.vim/plugged')
" Add your plugins here.
Plug 'tpope/vim-fugitive'
" Initialize plugin system.
call plug#end()
The Plug 'tpope/vim-fugitive' line is the core of it. 'tpope/vim-fugitive' is the GitHub repository path for the plugin. vim-plug knows how to fetch plugins from GitHub this way.
Finally, save your .vimrc file. Now, when you open Vim, you need to run the PlugInstall command.
Open Vim and type:
:PlugInstall
Press Enter. vim-plug will read your .vimrc, see that tpope/vim-fugitive is listed, download it to ~/.vim/plugged/vim-fugitive, and make it available for Vim.
You should see output indicating the download progress. If it succeeds, you’ll see a message like "All plugins installed."
To verify, you can try loading the plugin. For vim-fugitive, you can check its status by typing :Git inside Vim. If it works, you’ll see Git status information.
If you want to update a plugin later, you’d run :PlugUpdate. To remove a plugin, you delete its Plug line from .vimrc and then run :PlugClean.
The most surprising thing about managing Vim plugins with vim-plug is how seamlessly it integrates into the Vim editing experience itself, making plugin management feel less like an external task and more like an extension of your configuration.
Consider this scenario: you’ve installed a plugin, but it’s not behaving as expected. You check the plugin’s documentation, but it’s unclear. The common instinct is to reinstall or reconfigure. However, vim-plug has a built-in mechanism to resolve conflicts and ensure plugins load in the correct order, which is often overlooked. You can explicitly control the loading order by placing Plug declarations strategically within your .vimrc or by using after directives.
This isn’t about just installing plugins; it’s about making them work together. You’ll soon want to explore how to manage different plugin versions or how to lazily load plugins to speed up Vim’s startup time.