Mike Knepper


February 21, 2014

When I began my apprenticeship a little over a month ago, I decided to use Vim exclusively whenever I was working on 8th Light projects. I still used Sublime Text 2 on Tuesdays and Thursdays at WireHarbor, but gradually I got more and more comfortable with Vim. Earlier this week, I arrived at 1871 and fired up the WireHarbor code in… Vim. It appears the end of Sublime Text 2 is nigh. Here are some thoughts from a recent convert.

Earliest experiences with Vim

Prior to committing to learning Vim, my only experience with it came during merge conflicts in git, which by default open up vim for resolution. These were scary experiences because not only was git telling me something unexpected and seemingly complicated was going on, but I was almost completely unable to type or even exit the editor. Facing the daunting task of learning two things (the horror!), I adjusted my global git settings to make Sublime Text 2 my default editor. This helped decrease the intimidation factor of merge conflicts, which I soon learned how to interpret and resolve.

Inspired to change

The first time I came in to 8th Light to talk about my Tic Tac Toe application, I sat for an afternoon with craftsman Josh Cheek. I couldn’t believe the speed with which he navigated directories and edited files. I knew generally that many computer programmers used Vim, but I had never really seen it in action at the hands of a master. Josh graciously switched to Sublime when we started pairing later in the day, but a seed had been sown in my head–maybe Vim was worth learning.

At the beginning of my apprenticeship, my mentor Rylan recommended I start seriously considering Vim. He had recently quit Sublime cold turkey and was going through some transitional pains, but he noted that many 8th Light-ers used Vim and if I got more comfortable with it, I’d be more comfortable pairing with random people on various projects. It wasn’t a requirement, but I recognized it would be valuable and so decided to use Vim exclusively when working at 8th Light.

Getting started

Open up your terminal app of choice (iTerm2, personally) and enter the command vimtutor. This launches a nice tutorial for learning the basics of Vim. It can be a little boring, especially going through it multiple times in an effort to get all the lessons to stick, but I did find it very helpful. As is often the case, though, there’s a big difference between following a step-by-step tutorial and applying those lessons to a real project. Vimtutor can seem like a random exercise to just slog through and be done with, especially given its bare-bones, black-and-white appearance. If you want to make the leap into using Vim in an actual project, you’re going to want to tweak several settings to your liking; otherwise you’ll go nuts with the stark defaults and hop back to Sublime.

The main file responsible for customizing Vim is the .vimrc file, located in your home directory (~/.vimrc). When I got started, I simply grabbed a random .vimrc file I found from someone’s blog and used it as a starting point, figuring I’d tailor it to my liking once I understood it all better. So, for anyone interested:

" Required for Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" Color settings
set t_Co=256
syntax on
colorscheme gruvbox
set background=dark

" Key-mapping settings
map <leader><leader> :NERDTreeToggle<CR>
imap <C-c> <ESC>
map <leader>r :RainbowParenthesesToggle<CR> :RainbowParenthesesLoadRound<CR> :RainbowParenthesesLoadSquare<CR> :RainbowParenthesesLoadBraces<CR>

" Movement settings
set nostartofline
set backspace=indent,eol,start

" Visual settings
let g:NERDTreeWinSize = 26
set splitright
set cmdheight=2
set number
set ruler
set showcmd

" Search settings
set incsearch
set hlsearch
set ignorecase
set smartcase

" Indentation settings
set autoindent
set shiftwidth=2
set softtabstop=2
set expandtab
filetype indent on

" Alert settings
set confirm

" Vundle plugins
Bundle 'gmarik/vundle'
Bundle 'kien/ctrlp.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'kien/rainbow_parentheses.vim'
Bundle 'scrooloose/nerdcommenter'

I’d recommend installing Vundle as your first step. Vundle is a Vim plugin/package manager that makes adding plugins very easy. Read the README installation guide to get it up and running.

Some highlights

  1. NERDTree is an extremely helpful way to browse your file directory, open new files, and add/delete/rename files and folders. Critical.
  2. Ctrlp is a fuzzy search for files. Nearly as essential.
  3. Rainbow Parentheses highlights matching ( ), [ ], and { }, which can be quite helpful sometimes (especially in JavaScript, I would imagine). The default way to turn them on/off is by entering the command :RainbowParenthesesToggle, which is obnoxiously long, so you’ll notice in my Key-mapping settings section, I created a shortcut: \r (Note: forward-slash \ is the default “leader” key; I’ve seen lots of people remap it to be the comma, but I haven’t found \ too uncomfortable so I haven’t bothered changing it.)
  4. I’ve had a surprisingly difficult time getting color schemes right. There are a surprising number of factors at play, unfortunately, including Terminal and iTerm2 handling colors slightly differently, many color schemes recommending Pathogen installation (an alternative to Vundle), and other color schemes (like mine, gruvbox) requiring being manually downloaded and placed in the ~/.vim/colors directory.

Closing thoughts

As I mentioned in the intro, I’ve started using Vim outside 8th Light on other projects, including WireHarbor. To be honest, it’s a little hard for me to explain why, exactly–there are still a few things that Sublime Text 2 handles noticeably better than Vim (at least at this point), including keeping multiple files open and “at the ready” in different tabs and auto-completing words and tags. I still think Sublime Text 2 is a great text editor and I’m certainly not uninstalling it any time soon, but it’s taking a definite back seat to Vim in my workflow going forward.