How Emacs beat vi in the Editor Wars
August 11, 2020  

In these dark times, we are all in sore need of good news. Thankfully, I can report some: Emacs has defeated vi in the Editor Wars!

Some people, laughably, believe that vi is more popular than Emacs. Fortunately, these fools are completely wrong, and it is easily proven.

Here’s how. Take out an iPhone and get it set up with a Bluetooth keyboard. Open a web browser and start typing in the address bar. Try a few Emacs key bindings: control-a (move-beginning-of-line); control-e (move-end-of-line); control-b (backward-char); control-k (kill-line); control-d (delete-char); control-y (yank).

That’s right, Emacs is in your phone browser! With more than 2 billion iPhones shipped, that’s more than 2 billion Emacs installations. And if you try other phone or desktop browsers you just might find that Emacs is in those as well. But you won’t find vi.

QED, losers!

The importance of key bindings

Perhaps you are wondering, is it really fair to judge the dominance of Emacs solely based on key bindings? What about all of the other ways in which Emacs is superior to vi?

Rest easy, friend. Consider that most users of any editor only use basic features, such as the ones mentioned above (moving to the end of a line, deleting a line, etc.). For these users, Emacs and vi are functionally equivalent—each as powerful as the other.

So, if two editors have the same functionality, what distinguishes one from another? It is the way that the editor exposes editing functions to the user—the user interface. And for Emacs and vi, which were created in the early days of text-based terminals without mice, that means the keyboard interface, i.e., their key bindings.

How Emacs key bindings are superior to vi key bindings

We have proven that Emacs key bindings are superior to vi key bindings: Emacs has won the marketplace, while vi heads to extinction. But why are they better?

To answer this we defer to Larry Tesler, who developed the now-ubiquitous editor functions, Cut and Paste. Before Cut and Paste, moving a block of text in a document was a complex, multi-step command in editors: it was a mode of the editor, distinct from other operations such as moving the cursor or inserting characters.

Tesler’s Cut and Paste enables moving a block of text without introducing a new mode. In between the operations of Cut and Paste the user can insert characters and move the cursor as usual; the normal mode of insert/cursor movement, combined with a simple Cut and a simple Paste, allows you to move a block of text. You don’t have to learn a new, complex mode for this.

This is what Tesler called modelessness. Now, in reality every editor has more than one mode, but Tesler argued that fewer modes make editors easier to use, and Emacs and vi demonstrate this nicely.

There’s an old joke about vi: Once you use vi, you’ll never quit. This of course refers to the fact that frequently in vi you’ll get stuck in a mode that you can’t get out of, because you’ve forgotten what mode you are in, or you’ve forgotten the key binding to get to the mode in which you can exit vi. So for example, vi has a mode where you can insert characters; a different mode where you can move the cursor, delete lines, and so on; and yet another mode in which you can do things like quit the editor. And depending on which mode you are in, you have to hit a different sequence of keys to quit the editor. That’s why “How do I quit vi?” is such a popular Google search.

Emacs, in contrast, starts out in a mode in which you can do all of those things. It crams all of that functionality into one mode by, you guessed it, using a lot of key bindings involving modifiers like the Control key and Meta key.

Emacs, to be sure, has many more modes than this, however, most of these modes simply extend the fundamental mode with more key bindings to invoke the additional functionality. Thus the quit command can be invoked by the same key binding in any mode! Another way of putting it is that all of the finger knowledge that an Emacs user has will probably apply regardless of what mode Emacs happens to be in.

This is why Emacs, and not vi, is present in the iPhone browser. It allows the browser to have advanced functionality (such as moving to the beginning or end of the address bar) without introducing a new mode, and without interfering with the simple task of inserting characters. This ensures that users who don’t need or aren’t even aware of the advanced functionality will never get stuck in a different editing mode.

Beyond Emacs

Emacs is a wonderful editor but nowadays editors are not so important. Most of the time we are consuming content instead of generating it. The web browser is now the center of the software universe. And although browsers have a little bit of Emacs in their address bars, the rest of their user interface has taken a big step backwards from Emacs: their keyboard support is poor. It’s impossible to operate most web browsers using only a keyboard, without a mouse or touchscreen.

There have been a few side efforts to add keyboard navigation to popular web browsers. Conkeror has been my favorite, but it doesn’t seem to have much of a future, as it depends on old, unsupported technology (XULRunner). Of current efforts, I like Tridactyl, but it only works with Firefox (for now), and its key bindings are inspired by vi, not Emacs.

A more fundamental problem is that browser makers simply don’t care about keyboard navigation, or at least they are incompetent about it. Their extension capabilities are crippled and their key binding support is too. We may be waiting a long time for the Emacs of web browsers.