Why Vim is so much better than Atom

Leo Allen
Makers
Published in
8 min readAug 4, 2016

--

by Leo Allen

Ever since coders have started to code, they’ve been arguing over which tool is the best for getting their job done. Although these debates can easily descend into interminable editor wars it’s an important thing to consider, particularly when you consider that as a programmer you’ll be spending the majority of your working time typing into whatever editor you decide to choose.

Recently I’ve noticed a lot of the students who are learning to code at our intensive bootcamp here at Makers Academy have begun switching to Atom, an open-source editor made by developers at GitHub. As impressed as I’ve been with Atom, I personally believe you can have a far more productive experience using a text-editor that first emerged nearly 40 years ago — even if you’re just beginning to learn to code.

Enter Vim

Vim is an open-source and free clone of vi, a text-editor developed in 1976 by Bill Joy. It is generally run in the terminal, and when you first look at some code in Vim it admittedly does still look like something that was developed long before people discovered that computers could actually be friendly to humans:

If you type vim into your Unix-based terminal something similar probably will come up. If vim isn’t installed you can install it on a Mac using homebrew by running brew install vim — I’d recommend doing this anyway as the default version on a Mac is pretty out of date.

While you’re at it I strongly recommend taking Jilles Soeters’ advice to badassify your terminal and shell — once you switch to Vim you’re going to be spending even more time in the terminal and you want the experience to be as enjoyable as possible.

What Atom does better

Before I start extolling the virtues of Vim, I’ll be honest: there are some things that Atom does better…

Configuration and set-up

Out of the box Atom is fully-featured: it already has syntax highlighting, Git integration, file management and so on. And if you want to change any of the configuration steps, there’s a nice visual Settings screen which guides you through the process.

Vim on the other hand requires a little more work, although it’s really not as hard as you might assume:

Don’t worry if at the moment you don’t understand what’s going on, at the beginning I just started with Thoughtbots base template and gradually tweaked it to my needs as my knowledge of Vim deepened.

Packages

Atom has an impressive package management system, allowing you to add any of the thousands of community-created packages to enhance your editor by simply searching for and installing packages, all from inside of Atom.

Vim lacks such a simple and clean interface for installing and finding packages, but fortunately someone created Vundle, a plugin manager that works very similarly to Ruby’s Bundler (hence the name Vundle). Once you get it installed, you can then add new plugins by defining the GitHub repo where the plugin is stored, e.g.

Plugin 'tpope/vim-surround'

and then type :VundleInstall to install it.

Vundle is not quite as easy as Atom’s system, but once you get it setup it’s actually almost as quick. You can also quickly search for plugins using the website VimAwesome — you’ll soon see you can do pretty much anything in Vim with the right plugin.

Themes

GitHub have always paid great attention to design and Atom is no exception, coming pre-installed with some great looking themes and again offering a simple interface for finding and installing more.

But we can once again use Vundle to install themes, in exactly the same way we installed plugins, and use VimColors to search for new ones.

Try getting gruvbox using Vundle and then setting it as your theme by adding colorscheme gruvbox to your .vimrc.

We can now see that things already looking much better:

What Vim does better than Atom

Although we’ve seen that setting Vim up is not quite as easy as setting up Atom, it’s really not that difficult. And although there’s still a bit of a learning curve left, we can now start looking at the real advantages of using Vim over Atom.

Navigating

When you first start using Vim, it seems counter-intuitive. It forces you learn numerous different editing modes such as Normal, Insert and Visual; and you can’t use a mouse. Yet this in fact is where Vim starts to really show its power. Navigating around code in an editor like Atom, you’ll eventually need to move your hands off the home-row of your keyboards and either pick up a mouse or use the arrow keys, hugely slowing you down if you’re a touch typer (which you should be).

Vim gets around this problem by having an Insert mode (basically the same mode that Atom offers) but an additional Normal mode where all of the keys become movement keys, so that for example j moves your cursor up and k moves it down.

You can switch between these modes by pressing i to go into insert mode and Escape to go back into Normal mode. I speed this up by remapping jj to perform the same function, so my fingers don’t have to leave the home key to find the escape key:

inoremap jj <ESC><CR>

This is an example of how Vim’s ability to customise almost anything can really speed up your workflow.

To start learning how to use Vim my colleague Spike has a great guide to getting started which I’d recommend starting with.

Navigating files

When coding we’re constantly jumping between files, so it’s crucial that our editor has a powerful tool for navigating between them. Although Atom has a Find in Buffer tool, the Vim package CtrlP works in a similar way but is significantly more useful.

At it’s most basic you open Vim from the root folder of the project you’re working on, type Ctrl and P to open the fuzzy-finder and then start typing the file you want to open. Because it’s a fuzzy finder you don’t need to type all the letters of the file you’re looking for to bring it up:

So far, no different from Atom’s finder. But CtrlP gives us much more. We can open that file just by pressing Return, but we can also press Ctrl-V to open a buffer in a split:

Or Ctrl-T to open a buffer in a new tab (the tabs are shown at the top of the file):

Or if the file doesn’t exist, you can press Ctrl-Y to create a new file.

Given how many files you end up juggling in a large web app, having these shortcuts will end up saving you a tonne of time. In addition, I would recommend remapping your Caps Lock key to Ctrl, as once you start using Vim with CtrlP you’ll be finding yourself using Ctrl far more than Caps Lock.

Another use CtrlP has is to quickly open a file and its related test in a window next to it — particularly crucial if you practice TDD like we do at Makers Academy.

Personally it was the need for a tool that worked seamlessly with my TDD workflow which was why I finally gave up on Atom and switched over to Vim. I had become frustrated with a workflow where I would write a test, switch windows to the terminal to run my tests, and then switch back again to make them pass.

With Vim, because it’s already based in the terminal, it’s trivial to run tests directly from Vim, either by running a terminal command by prepending :! to it, such as

:!npm test

or even better by using a plugin like Vim RSpec that adds shortcuts to various test commands, as described on Thoughtbot’s blog.

Taking inspiration from Gary Bernhardt’s Vim/TDD workflow I also have remapped the return key so in Normal mode it saves my files and repeats the last command:

nnoremap <CR> :wa<CR>:!!<CR>

This has radically changed my TDD workflow — now with one press of the Return key, I can run my tests, immediately see their results and press the Return key to go straight back to my code. It’s a workflow that’s so fast that often when I’m pairing I’m told by my pair that I need to slow down so they can see what’s happening with the tests!

Pairing

On the subject of pairing, this is another of Vim’s strengths. You can use Vim with Tmux, a programme which allows someone else to SSH directly into your computer, and not only see your Vim screen on their computer but jump in and start editing as well. It takes a little bit of setup to get around some of Tmux’s intricacies but it’s worth it once you get going — you can even pair remotely using the same Vim session.

Going further

If somehow you’re still not convinced, it’s worth pointing out that what I’ve talked about here is just the tip of the iceberg. There’s so many more things I love about Vim:

  • Airline gives you a nice status bar at the bottom of your Vim like the ones in my screenshots
  • NerdTree is a great partner to CtrlP for browsing files from within Vim
  • Ag.vim can search in all your files almost instantaneously
  • EasyMotion will speed up you moving around Vim in Normal mode
  • AutoFormat correctly formats your files with press of a button
  • Syntastic checks your files for syntax errors as you type
  • Finally all of Tim Pope’s Vim plugins are worth a look — they integrate Vim with Rails, Git and loads more

So hopefully I’ve done enough to convince you to at least give Vim a try — once you’ve gotten over it’s learning curve you won’t go back, and you’ll finally be able to call yourself a hipster hacker:

Originally published at blog.makersacademy.com on September 30, 2015.

--

--