I’ve changed code editors quite a bit. I remember building my first webpage in middle school on a copy of Microsoft Frontpage. It was about tree frogs. The ’90s, man…
Long after that I moved to Dreamweaver, then Coda, then to Sublime Text. It seemed like every code editor I switched to became faster and more powerful. The editor got leaner, but was made powerful through plugins.
Earlier this year a friend and I went to the Frontend Tooling conference by Sparkbox. People talked about tools like Grunt, Capistrano, Vagrant and code editors. Adam Simpson demoed his Vim setup and it blew my mind.
So now, after some warming up, it’s time to switch to another code editor. I’m switching from Sublime Text to Vim. Here’s why and how you can switch to Vim from your current editor, too.
So, why use Vim?
There’s a couple reasons why Vim appeals to me over something like Sublime Text or Atom.
If you’re on a Unix-based OS you probably have it installed already. All of your preferences go into a single
.vimrc file that (usually) is in your home directory. On top of that, much of web development involves using the command line. Using Vim removes having another app in your workflow.
Because Vim is found on so many machines, you can easily copy your settings to a second computer or a server you frequently SSH into. Just copy over your
.vimrc and you’ll have your usual setup on other devices.
Vim is lean right out of the box, but can be very robust depending on your
.vimrc file and any plugins you add. The community is massive and is full of great addons like Pathogen, Fugitive, NERDtree, ctrlp and much more.
Need to modify an existing plugin? Just fork the plugin and clone it into your
~/.vim/bundle/ directory (if you have Pathogen installed).
Starting Vim without ripping your hair out
Jumping into Vim can be…overwhelming. Fortunately, there are some practical ways you can start without going crazy.
Don’t bite off more than you can chew
Yehuda Katz has a fantastic article about making the transitioning to Vim. He mentions that many Vim users encouraged him to dump the mouse and just use the keyboard on day one. That just doesn’t work for people leaving apps like Sublime Text.
His recommendation is (links added by me) “to use MacVIM, NERDTree, PeepOpen (or command-t), and use the mouse, arrow keys, and familiar OSX’isms all you want.”
This allowed him to slowly learn Vim while he was in his familiar setup.
Configure your .vimrc file
.vimrc file can help establish some sensible default settings.
For example, you probably are used to line numbers so you’d want to add
set number to your
.vimrc file. It’s also a good idea to trim trailing whitespace so adding
autocmd BufWritePre * :%s/\s\+$//e will help, too.
Tim Pope’s vim-sensible repo is a great place to start if you don’t have a
.vimrc file ready. I come from using Sublime Text so here’s my current .vimrc file.
Print out a cheat sheet and learn a new command (or two) every week
Downloading or printing a cheat sheet is a good way to learn the many different Vim commands. A couple of my favorite are:
dd- Delete (cut) a line
p- Put (paste) before cursor
vi[surrounder]- Selects within. For example, using
<div class="foo bar baz">will select
foo bar baz.
o- Inserts new line below current
Keep practicing and asking questions
Learning a new tool involves doing things again and again. Nobody jumps into something new with expert knowledge. So don’t be afraid to ask what you may think are “dumb questions”. Chances are fifty others have asked the same question you have.
Lastly, don’t feel bad if Vim doesn’t work out for you. There’s a reason for so many different code editors. Not all of them will work for you.
Just as long as you still aren’t using Microsoft Frontpage.