How I

Ben McCormick

Web developer

Durham, North Carolina

Who are you and what do you use Vim for?

I’m Ben McCormick, a web developer from Durham, North Carolina. I currently work at Windsor Circle, where I’m the lead front end developer. I use Vim for writing code (mostly JavaScript and Python) and blogging. Mostly I’m using the terminal version of MacVim, though I’ve also experimented with NeoVim recently, and will occasionally use Vi-mode in other editors if I want something more graphical. I started using Vim as my main editor about 2 years ago, and am in it pretty much daily. Last summer I wrote a blog series on Learning Vim in 2014 that got a good bit of attention. It’s intended as a starting place for users wanting to learn how to use Vim as it exists today.

Introduce us to your Vim config.

My Vim config is somewhere in the middle ground between minimalist and power user. It currently sits at around 300 lines with the first 100 being dedicated to plugins (don’t worry, its heavily commented, I don’t have 100 plugins), the next 100 or so lines on general configuration, and the last 100 on plugin configuration. I’m using Vundle for managing the plugins and I’m quite pleased with it. I’ve heard that Neobundle is also great, but until I have an issue with Vundle I see no reason to switch. Having a good plugin manager is important, having the current best, not so much.

My plugins get divided into 2 areas, themes/syntax and functional. The theme part is pretty basic, I load in solarized and the base16 theme, and then occasionally switch between the different options. Right now I’m using base16-flat, but my favorites are definitely base16-eighties and solarized light. Syntax stuff is similarly boring, I have a few “improved” syntax packages for JavaScript, JSON and Markdown, and then a few more for obscure languages/syntaxes that Vim doesn’t ship by default. The functionality side has more meat though.

" Functionality

" ### Indispensable

" ctrlp is file fuzzy search
Plugin 'kien/ctrlp.vim'
" Ack.vim uses ack to search within files
Plugin 'mileszs/ack.vim'
"Airline provides a stylish appearance for the styleline
Plugin 'bling/vim-airline'
" Syntastic provides syntax info
Plugin 'scrooloose/syntastic'
"Show git info in the gutter, sad that it and syntastic fight for space though
"Plugin 'airblade/vim-gitgutter'
"Integrate with tmux
Plugin 'christoomey/vim-tmux-navigator'
"Provides Sublime-Text like smart completion of braces, parens and such
Plugin 'Raimondi/delimitMate'
" Great helpful autocompletion (requires a separate compile step)
Plugin 'Valloric/YouCompleteMe'
"Easy commenting in Vim
Plugin 'tpope/vim-commentary'

" ### Use sometimes

"Nerdtree provides a file explorer, which is sometimes useful. Mostly ctrlp handles file finding though
Plugin 'scrooloose/nerdtree'
" fugitive provides git bindings in Vim.  Don't use too much, but useful for blame
Plugin 'tpope/vim-fugitive'
" Surround is useful for adding surrounding tags to elements (especially html and quotes)
Plugin 'tpope/vim-surround'
" Allows vim-surround to be used with . command
Plugin 'tpope/vim-repeat'
"Adds convenience stuff for writers
Plugin 'reedes/vim-pencil'
"Provide snippets functionality in Vim
Plugin 'SirVer/ultisnips'
"Standardize whitespace
Plugin 'editorconfig/editorconfig-vim'
"Gives smart completions for Javascript
Plugin 'marijnh/tern_for_vim'

" Experimenting with these

Plugin 'tpope/vim-unimpaired'
Plugin 'itspriddle/vim-marked'

" Not Using anymore/right now
" Provides an alternative way to move quickly through files
"Plugin 'Lokaltog/vim-easymotion'
" Provides integration with  I mostly query dash directly
"Plugin 'rizzatti/dash.vim'
"Tries to handle ctrlp/ack.vim/buffer switching tasks, but lacks the attention
"to detail and documentation of those plugins
" Plugin 'Shougo/unite.vim'
" Plugin 'Shougo/vimproc.vim' "Unite dependency
" Cool way of setting up projects
"Plugin 'tpope/vim-projectionist'
"Plugin 'merlinrebrovic/focus.vim'
"Plugin 'tpope/vim-eunuch'
"Plugin 'terryma/vim-multiple-cursors'

I divide my plugins up into 4 categories: Indispensible, Use Sometimes, Experimenting, and Not Using. By far my most important plugins are ctrlp, ack.vim and the vim-tmux-navigator. Vim’s built in file management is, if not broken, at least wildly inconvenient compared to competing editors like Sublime Text. Typing in paths is great if you’re working on a small project, but for larger projects with deep paths it’s important to be able to use a mixture of strategy including fuzzy finding and content searches. I wrote a piece last fall detailing in depth how I use ctrlp and ack.vim along with NerdTree and built-in methods to manage my files.

Syntastic is great if you’re using syntax checking tools, which I use heavily for JavaScript development. I use tmux in my terminal for managing the different work I usually have going on side by side. Tmux-Navigator provides a common set of key-bindings that you can use to navigate between tmux-splits and vim splits. It makes the experience of using both much nicer, and generally provides a “though-free” way of moving between Vim and the command line.

The other plugins I’d want to highlight in Indispensible and Use Sometimes are YouCompleteMe and UltiSnips. YCM is a great tool for syntax completion that works with a variety of different sources. UltiSnips is a snippets library for Vim that is really nice to use. I hate that every snippets library seems to have their own syntax, so stuff like this can never be reused across editors or environments, but otherwise there’s very little to complain about with UltiSnips.

Beyond plugins, my config isn’t super exciting. Much of it unfortunately is dedicated to making Vim behave like a modern computer program, assuring it that it’s not 1990 anymore and we have the system resources to provide crazy luxuries like line numbers and background files. I try to stick close to baseline Vim behavior as much as is reasonable. I keep leader mapped to \\. I know many people prefer to remap it to ,, but I use comma all the time for its built-in function of moving backwards when searching for a character in a line. I recently saw an article suggesting to map the space key to leader and I may consider trying that. I use the vim-pencil plugin to use different wrapping rules and motions when writing text than I use for code.

You can see a snapshot of the full config from the time of this interview in this gist. To see the latest, you can look in my dotfiles repo.

What have been the most useful resources for you to learn Vim?

By far the most useful resource for me was Practical Vim by Drew Neil. It’s a great read for understanding the philosophy behind Vim, and slowly building up your skills. I’m about due for a re-read actually. Drew’s screencasts at Vimcasts are also great, though I personally always prefer text to video. I also learned a lot from looking at other peoples configs. My vimrc was originally based on Wynn Netherland’s vimrc, though both have diverged considerably now. I also learned a lot from reading the recommended configuration from Janus a “vim bootstrap” project. I don’t recommend taking a heavyweight config like that to start, I think its better to build up your own, but projects like that are great inspiration for what is possible.

Share a piece of Vim script you’ve written and talk about what it does.

I actually can say without shame that I’ve never written any Vimscript beyond the very simple stuff used in the Vimrc config. I prefer to invest my time in projects and tasks that have as much long term value as possible. Since Vimscript is limited to just Vim, and Vim has such a great ability to work with command line tools and scripts, I prefer to write scripts to find or manipulate files on the command line level, and then call them from Vim if needed. The fact that Vimscript is not a greatly loved language helps make this easier.

I’m currently working on a library to define “projects” on the command line, groups of files that you can then search in list or pick from using command line tools. I’ll be excited to use that with Vim, but since its written as a command line tool in Python, the great thing about it is that it ends up being editor agnostic, at least for most use cases.

What have you been working on recently in Vim?

I spend a large chunk of my days in Vim, between writing code and writing posts for my blog. I’m in more meetings at work these days, so it may not be quite as much as it used to be, but Vim is definitely constantly open. In addition to the project I mentioned above and work, I’m working on starting a new series about jQuery on my blog.