How to Install Plugins in Vim using VimPlug

Recently, I started using Vim as my default code editor, instead of Textmate.

After gaining a reasonable proficiency in it, I started exploring other things that could be done in it.

It turns out that Vim can be extended to do almost anything you want. If a solution for your problem hasn’t already been made, you can make one yourself.

However, I could not find a guide to installing plugins in Vim. Eventually, after some trial and error, (and looking at others’ ~/.vimrc’s) I figured out a way. Here it is:

Install VimPlug (taken from VimPlug’s Github page):

If you’re on MacOS or Linux, go to the Terminal and then run:

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

If you are on Windows, open cmd or Command Prompt and run:

md ~\vimfiles\autoload
$uri = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
(New-Object Net.WebClient).DownloadFile(
  $uri,
 $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
    "~\vimfiles\autoload\plug.vim"
  )
)

These commands simply download plug.vim and copy it to vim’s “autoload” directory.

Now, set up your ~/.vimrc:

In your Terminal (or Command Prompt) enter:

vim ~/.vimrc

Then, at the top of the file, enter these lines (I’m assuming you have at least a basic knowledge of using Vim. If not, check out Vim 101):

" VimPlug setup  
call plug#begin('~/.vim/plugged')

 " Enter plugins here`

 call plug#end()

Next, find the plugins you want and specify them in ~/.vimrc:

The easiest way to find vim plugins is to browse Vim Awesome. I chose Airline, a utility that draws a nice status line at the bottom of my vim window.

Click on “VimPlug” as shown:

In your Terminal (or Command Prompt), type:

vim ~/.vimrc

Replace the line that says  "Enter plugins here, with the line that VimAwesome gave you. In this case, it was Plug 'bling/vim-airline'. Make sure to save with :w.

Finally, install it!

In Vim, type :PlugInstall.

If all went well, you should see Finishing … Done!

Congratulations! You now know how to install VimPlugins. Just place any new plugins you find inside the lines in your ~/.vimrc where you call VimPlug and then run :PlugInstall to finish.