Vim For Developers: Part 5— Plugins

David Ondrich
7 min readAug 11, 2020

Check out the previous posts in this series if you haven’t already!
Vim for Developers: Part 0 — Why Vim?
Vim for Developers: Part 1 — The Basics
Vim for Developers: Part 2 — Advanced Basics
Vim for Developers: Part 3 — Advanced Vim
Vim For Developers: Part 4 — Custom Configurations

TL;DR — If you’re somewhat familiar with NeoVim/Vim and you’re just looking for a badass config, you can check out my dotfiles here.

Extending Vim?

If you’ve been following along this whirlwind of a ride that is learning Vim, you’ve probably noticed that this inconspicuous, little text-editor has seemingly endless functionalities and features. Why then would we need to add plugins? There’s already too many features for one man or woman to know!

The first answer is: abstraction — as developers that’s our bread and butter right? Some things are just a little cumbersome to accomplish in Vim, and can be made absolutely delightful with a little plugin.

The second answer is: go beyond the limits of text-editor — I said it way back in the first post of this series.

The thing about Vim is it’s not an IDE
- Myself, on Vim

And it’s still true. Vim is a text-editor, not an IDE. Plugins will allow us to take the very most-useful features of IDEs, and bless our dear Vim with them.

How to Add Plugins to Your Vim

Given that this series is called Vim For Developers I’m going to assume you’re familiar with the concept of package managers. Luckily for us, Vim has many great ones to choose from for us to manage our plugins with!

The particular one I prefer is called vim-plug and comes to us from the prolific junegunn. You will see him crop up often in the world of Vim plugins, he’s written some of the best and most useful plugins out there. Some of them we’ll see in this post.

Installing Vim-Plug

Vim-Plug has some excellent documentation on its GitHub, but installing it is a piece of cake. Run the commands below for your relevant OS and preferred Vim (Vim or NeoVim).

Vim

Unix

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

Windows (PowerShell)

iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
ni $HOME/vimfiles/autoload/plug.vim -Force

Neovim

Unix, Linux

sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

Linux (Flatpak)

curl -fLo ~/.var/app/io.neovim.nvim/data/nvim/site/autoload/plug.vim \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Windows (PowerShell)

iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
ni "$env:LOCALAPPDATA/nvim-data/site/autoload/plug.vim" -Force

How To Use Plugins With Your .vimrc

Now that we’ve got vim-plug installed it’s time to start putting it to use. Like we’ve done in previous posts I figured we’d walk through my .vimrc file and show you how to use plugins, and which plugins I’m using.

It should be noted that some of these plugins require additional setup beyond the .vimrc to get going. They’re mostly all well-documented on their respective GitHub pages better than I could explain here, so check them out if you decide to use any.

call plug#begin('~/.config/nvim/bundle')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'scrooloose/syntastic'
Plug 'tpope/vim-surround'
Plug 'bling/vim-airline'
Plug 'morhetz/gruvbox' " Theme
Plug 'scrooloose/nerdcommenter'
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-fugitive' " Git Wrapper
Plug 'wesQ3/vim-windowswap' " Window swapper
Plug 'ryanoasis/vim-devicons' " Icons for NERDTree"
Plug 'terryma/vim-smooth-scroll'
call plug#end()

Breakdown

The first line you’ll see is:

call plug#begin('~/.config/nvim/bundle')

This is how you start the section of your config file that tells Vim which plugins to load. The file-path '~/.config/nvim/bundle' is the default location for NeoVim. If you’re using regular Vim it will likely be:

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

Finally after all your plugins you call:

call plug#end()

This is the same for both NeoVim and Vim.

Installing Your Plugins

To use your new plugins you must first install them. This is an easy two-step process.

From your current Vim window run:

:source <path to your config file>
//Default NeoVim
:source ~/.nvim/init.vim
//Default Vim8
:source ~/.vimrc

This updates your current session with your newly saved config file.
Then run:

:PlugInstall

A new window will open and you’ll see the repos being cloned from GitHub. And that’s it! Vim-Plug handles it all for you that simply!

Plugins I Use

Plug 'neoclide/coc.nvim', {'branch': 'release'}

This is likely the most useful plugin of them all, coc.nvim. Despite its unfortunate name, we’re very fortunate to have it! This plugin gives us the sweet, sweet IntelliSense that we’ve come to know and love in IDEs, and brings it to Vim.

CoC.nvim uses Microsoft’s language server protocol, so it should give you almost the exact experience as VS Code does, assuming you follow the install-guide correctly. Luckily coc.nvim is super-documented!

Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'

These two go together as they’re sort of a special case. Fzf is a fuzzy finder that is not specific to Vim, so you may have used it before. It is ported into Vim by the likes of junegunn and his extension fzf.vim. The first line is the path to your local instance of fzf, and the second line is the actual plugin. Check out the docs they’re superb.

Plug 'scrooloose/nerdtree'

NERDTree is a great extension that gives the sort of file-tree directory you’re used to seeing at the left (usually) of your IDEs. It’s great if you can’t remember what your file is called, but you know where it is!

Plug 'Xuyuanp/nerdtree-git-plugin'

You might be able to tell from the name… this plugin shows little icons to the left of the line corresponding to git changes. For example, if you add a line you’ll see a little green plus, remove a line you’ll see a little red minus, etc.

Plug 'scrooloose/syntastic'

This is a great syntax checking plugin that has a scary amount of support for different languages. If your syntax is incorrect a little popup will tell you what might have gone wrong.

Plug 'tpope/vim-surround'

I can’t tell you how useful I find this plugin. Besides coc.nvim it might be my most used plugin. It’s used to surround words or lines with things(?). It can also be used to change one type of thing to another (?). I’ll just show you.

See what I mean! You can find all the commands on vim-surround’s GitHub.

Plug 'bling/vim-airline'

This plugin gives you a nice little bar down by your command bar, like below.

Borrowed from vim-airline’s GitHub
Plug 'morhetz/gruvbox'

This is the theme I use, and I think it’s super sweet.

Plug 'scrooloose/nerdcommenter'

This allows you to comment out/in lines easily with the correctly denoted sign, based on the filetype you’re working in.

Plug 'jiangmiao/auto-pairs'

This plugin auto-closes your “” and ‘’ and [] and {}. Basically anything that can be opened, it will auto-close.

Plug 'tpope/vim-fugitive'

This useful plugin brings the power of Git into your Vim. I use it most often for git blame (I hate the term blame, let’s vote to switch it to git whomst-should-I-ask-about-this), and for viewing diffs.

Plug 'wesQ3/vim-windowswap'

This is a nice one for re-arranging your different window-splits.

Plug 'ryanoasis/vim-devicons'

This plugin is really a nice, little touch. But it’s the little things that count right?? It extends your NERDTree with little icons that correspond to the filetypes.

Plug 'terryma/vim-smooth-scroll'

Finally we have another nice, little touch. This plugin provides smooth-scrolling for your vim commands. For example, if you do ctrl-f without the smooth-scroll I find it tough to track where I was exactly. This adds a little animation to it.

Recap

There you have it, folks. Those are all the plugins I use every day, with my Vim, as a full-time software engineer. I firmly believe with a setup like this (feel free to steal mine exactly, I’d be flattered), you can be just as, if not more, productive than with an IDE.

Full disclosure: some of these plugins are easier than others to get working. It’s been a while since I’ve configured them so I don’t recall the specific tricks. But if you’re trying to set up any of them and run into trouble, drop me a comment and I’d be happy to help you out!

Up Next

If you’ve been following along up to this post, you probably know all the foundations to start using Vim as your everyday IDE. Of course, it will take some sweat and perseverance to start feeling comfortable, but you’ll be surprised at home quickly it comes. My advice would be to give it two weeks of full immersion to start seeing some improvements.

As for next posts in this series. I’ll write sporadically on Vim, smaller subjects and tricks, when they come to me or if I learn something new and useful. But besides Vim I plan to post regularly on developer-related topics. So stay tuned!

--

--