Switching to vim-plug

I’ve switched to vim-plug, a minimalist Vim plugin manager.

Recently I decided to switch my vim package manager once again, and this time the choice fell on vim-plug. (A couple of years ago I switched from Janus to Vundle)

The main part of this article consist of information found in the vim-plug README

Features

  • Single file. No boilerplate code required.
  • Concise, intuitive syntax
  • Super-fast parallel installation/update (with any of +job, +python, +python3, +ruby, or Neovim)
  • Creates shallow clones to minimize disk space usage and download time
  • On-demand loading for faster startup time
  • Can review and rollback updates
  • Branch/tag/commit support
  • Post-update hooks
  • Support for externally managed plugins

Installation

Download plug.vim and put it in the “autoload” directory.

Vim

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

Neovim

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

Commands

These are some of the commands that vim-plug provide.

PlugUpdate

Install or update plugins

PlugUpdate

PlugDiff

Examine changes from the previous update and the pending changes

PlugDiff

PlugClean[!]

Remove unused directories (bang version will clean without prompt)

PlugClean

On-demand loading of plugins

On of the main reasons for using vim-plug is its support for on-demand loading of plugins.

" NERD tree will be loaded on the first invocation of NERDTreeToggle command
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }

" Multiple commands
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }

" Loaded when clojure file is opened
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Multiple file types
Plug 'kovisoft/paredit', { 'for': ['clojure', 'scheme'] }

" On-demand loading on both conditions
Plug 'junegunn/vader.vim',  { 'on': 'Vader', 'for': 'vader' }

" Code to execute when the plugin is lazily loaded on demand
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
autocmd! User goyo.vim echom 'Goyo is now loaded!'

Configuration examples

A small sensible Vim configuration

call plug#begin()
Plug 'tpope/vim-sensible'
call plug#end()

Minimal version of my Go development configuration

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

Plug 'tpope/vim-sensible'
Plug 'SirVer/ultisnips'
Plug 'ervandew/supertab'
Plug 'honza/vim-snippets'
Plug 'peterhellberg/snippets'
Plug 'itchyny/lightline.vim'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'fatih/vim-go'
Plug 'nanotech/jellybeans.vim'

call plug#end()

let mapleader=','

color jellybeans

set completeopt-=preview
set modelines=3
set nobackup
set noshowmode
set noswapfile
set nowrap
set nowritebackup
set number
set shiftwidth=2
set tabstop=2
set termguicolors
set virtualedit=block

" Open new buffers
nmap <leader>s<left>   :leftabove  vnew<cr>
nmap <leader>s<right>  :rightbelow vnew<cr>
nmap <leader>s<up>     :leftabove  new<cr>
nmap <leader>s<down>   :rightbelow new<cr>

" Tab between buffers
noremap <tab> <c-w>w
noremap <S-tab> <c-w>W

" Switch between last two buffers
nnoremap <leader><leader> <C-^>

" NERDTree
nmap <leader>n :NERDTreeToggle<CR>

" SuperTab
let g:SuperTabDefaultCompletionType = "context"

" UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"

" Go programming
au BufRead,BufNewFile *.go setl filetype=go nolist noexpandtab syntax=go

au FileType go nmap <Leader>d <Plug>(go-def-vertical)
au FileType go nmap <Leader>do <Plug>(go-doc-vertical)
au FileType go nmap <Leader>ds <Plug>(go-def-split)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <leader>c <Plug>(go-callers)

let g:go_disable_autoinstall = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods   = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs   = 1
let g:go_fmt_command = "goimports"

augroup go
  autocmd!
  autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
  autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
  autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
augroup END

My full .vimrc is available in my dotfiles repository.

Peter Hellberg

My name is Peter Hellberg and I’m a Systems Developer in Stockholm, Sweden.