Plugin Managers for Vim

Plugin Managers for Vim

in

Plugins!!

Vim is a very simple text-based Text-Editor which can be transformed into a powerful IDE using plugins. This is the first of many posts I’ll write about vim plugins one at a time and how to set them up fully for a truly satisfying experience( custom tailored to your requirements ).

The first step to using vim plugins is finding them. You can find a list of trending vim plugins at vimawesome. Once you find a plugin, you have to install it. Most plugins have a README.md which you should read carefully before deciding to use them.

Maybe it requires an external dependency
Maybe it needs a particular version of vim
Maybe it requires NeoVim

After deciding upon that, installation needs to be done via a plugin manager like Pathogen or Vundle or Neobundle or Vim-plug or dein

So now starting upon my theme of taking one plugin at a time and setting it up, let’s start with plugin managers. I’ll highlight installation of a single plugin in Vim-Plug, the one I use and just brush up on the other plugin managers. For an example, the plugin we will be installing alongside the plugin manager is -

NERDCommenter - It adds superb commenting powers in vim

Vim-Plug is relatively newer so most plugins don’t refer to its installation instructions. The example I have taken is generic enough to consider most cases. The steps remain the same for all plugins, only the link changes and some of the options I specified change. So now onto Vim-Plug

Vim-Plug

A minimalist plugin manager and the one I use currently. Its features are highlighted at the top of README.md.As per what I wrote previously, you really should check out the homepage, i.e, the README.md and then decide whether this plugin is for you.

Installation

This involves a single file, plug.vim, which needs to be loaded when Vim starts and hence it is placed in ~/.vim/autoload

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

The plugin is fetched using curl which is a command line utility for downloading content from the web. Now to install plugins, you need to add the relevant section in your .vimrc. For the example plugin:

call plug#begin(expand('~/.vim/bundle'))
" Use single quotes

Plug 'scrooloose/nerdcommenter'
...
...
call plug#end()

So let’s understand what I did here:

  • called plug#begin() ( a function ) with an argument specifying where to install the plugins. Indicates that all lines below this contain plugin options
  • Used Plug 'scrooloose/nerdcommenter' to specify the plugin. Most plugins are distributed via github repositories nowadays so 'scrooloose/nerdcommenter' is a shorthand for https://github.com/scrooloose/nerdcommenter
  • called plug#end() to specify that no more plugins beyond this point

Here ~/.vim/bundle is where the plugins get installed. After adding this to your .vimrc, fire up vim and run :PlugInstall. This will start the installation in a side window with a nice progress bar while you can continue editing a file due to the asynchronous install.

To update plugins, run :PlugUpdate

To uninstall a plugin, remove it from your vimrc and run :PlugClean

To update vim-plug itself, run :PlugUpgrade

Extensive options are available for customising the experience. Many examples of installing are in the README.md with full documentation available by help.

Also for learning how to use a plugin, once a plugin is fetched, you are encouraged to read its documentation using :help plugin_name, in this case :help commenter.

Advantages:

  • Minimal and easy to use
  • Highly customisable plugin loading
  • Asynchronous install
  • On demand plugin loading and hence faster startup time for vim

Disadvantages:

  • None that bother me

Dein

Dein is the apparent successor of Neobundle both by the same person - Shougo.

One of the main reasons why I liked dein is because it supports asynchronous installation/updating of plugins, something which Vundle or Pathogen do not support. Neobundle provides this with the help of another plugin (vimproc), but I believe inbuilt support is better.

Advantages of using dein.vim:

  • Asynchronous Installs like vim-plug
  • Post installation hooks
  • Only Loads relevant plugins for a certain filetype and hence vim starts up faster

Disadvantages:

  • Relatively new and very little support
  • Help docs might be confusing sometimes due to too many features

Neobundle

Since dein.vim is the newer version as mentioned here, I’ll leave this out as deprecated

Pathogen

One of the oldest plugin managers for vim and hence it is slightly involved. Pathogen works on the principle that most plugins are available from git repos, so any git folder in ~/.vim/bundle is a plugin and hence it needs to be added to the runtimepath so that its data is loaded when vim fires up.

So coming to the advantages:

  • Old and ancient and hence extensive support
  • Very clean vimrc

Disadvantages:

  • Requires extensive effort from user side( some might consider this an advantage because you actually learn whats happening inside instead of an abstraction hiding it )
  • Help tags not generated automatically, need to update manually, need to uninstall manually, etc.
  • All plugins are loaded irrespective of filetype
  • Asynchronous installs only if you can type asynchronously

Vundle

The last but not the least, Vundle. Neobundle was a fork of this with more features and has now become dein. This is one of the first plugin managers I used, thanks to Lakshay and kept for a long time till I decided to switch to Vim-Plug. This is very nice and easy to use but just a little outdated as compared to Vim-plug.

The reason why I shifted from Vundle to VimPlug was because of its synchronous(blocking) install with no feedback on progress.

Advantages:

  • Simple
  • Automated updation and helptags generation

Disadvantages:

  • Blocking install
  • No post installation hooks
  • Loads all plugins irrespective of filetype. Slower vim startup

A more custom-tailored installation using Vim-Plug

This portion is only for those who have some experience in vim
If you are a vim learner, you may skip it right now

tern-for-vim - It adds support for javascript in vim.
tern_for_vim requires nodejs. (This is just an example, you don’t need to install this specifically)

I am choosing this Plugin because it has a build step alongside the usual installation and is valid for only some file types.

call plug#begin(expand('~/.vim/bundle'))
" Use single quotes

Plug 'ternjs/tern_for_vim', {'do': 'npm install', 'for': ['javascript', 'foobarlang']}
...
...
call plug#end()

What I did here:

  • called plug#begin() ( a function ) with an argument specifying where to install the plugins. Indicates that all lines below this contain plugin options
  • Used Plug 'ternjs/tern_for_vim' to specify the plugin. Most plugins are distributed via github repositories nowadays so 'ternjs/tern_for_vim' is a shorthand for https://github.com/ternjs/tern_for_vim
  • Now, if you read the README.md for tern_for_vim, it requires an additional step after installation, i.e., you need to run npm install in its directory. Now, with other plugin managers, you will need to do this yourself but Vim-plug offers the option to specify a post-install-hook i.e. the 'do' which specifies what needs to be done after fetching the source.
  • I know that this plugin is useful only for javascript and foobarlang ( a super awesome language that can code the universe!! ). So I denote that this plugin should only be loaded 'for' ['javascript', 'foobarlang']. If I did not specify this, it would have been loaded for all filetypes, slowing down startup.

Apart from the two non-default options above, there are many more. So how will you come to know about them??? Read the help docs like I did at the github repo.

Example of advanced usage

Vim-Plug takes the concept of loading plugins to another level by having an option to load plugins only when I call a certain function. For example let there be a plugin X which has a function Y. Now this plugin won’t be loaded at vim startup. Instead it will be loaded when I try to call the function Y. This plugin is valid for all filetypes but I only use it sometimes, so I set it up to only load when the function is called.

Ending

If you are a beginner in vim, I would suggest Vundle or Vim-Plug. Pathogen is too ancient and dein.vim is too complex. On a personal note, use vim plug as it has a simple interface for beginners and as and when you grow more experienced, you can fine tune your plugins using it, as in the custom-tailored example above. Even the pclub cordis use vim-plug. See here and here

PS

I consider myself a novice in vim with only 30-40% knowledge. So if my views seem biased towards Vundle or Vim-plug its because I used them. If there are any errors here, feel free to correct me in the comments.