on May 21st, 2006

What and What Now?

Vi and Emacs are two of the oldest and most popular text editors around. They’re both very powerful, but not easy to learn. For some idea of why you might want to make the effort, aimed at anyone who writes (types) a lot, you might want to see my previous article on Text Editors for Writers.

Very briefly, once learned, they’re the fastest way of editing text - but the unusual keystrokes might give you problems if you still have to use lots of other programs.

A Bit of History

Both of these editors have a long history. They go back over thirty years, which is a long time for any software to last. You can guess from this that they must be doing something right for some people at least.

The Editor Wars

Some people take their choice of editors really seriously. See the Wikipedia article for the Editor War to see how seriously. The two main sides in the battle are Vi and Emacs.

The Differences

Architecture and Design

  • Vi is fairly simple - it’s just a fairly small, fast text editor - it’s just a small program you run, which can open, edit, and save text files.
  • Emacs is an editor built around a Lisp interpreter - so it’s part editor, part programming language. Extensions and add-ons can be written in Emacs’ elisp language, and can be run inside Emacs, changing the way it works. This means that Emacs is almost infinitely extensible, and also quite big. It used to be thought of as quite slow, but on most modern systems, it’s actually pretty speedy.

Philosophy

  • Vi users claim they are closer to the Unix philosophy, because Vi does only one thing, and does it very well - editing text. Unix tools, traditionally, don’t try to do anything but what they’re designed to do.
  • Emacs users claim they are closer to the Unix philosophy, because Emacs is so extensible and programmable, and can be turned to do almost anything you want.

Personally, I think the Vi users have a better argument here, but it’s certainly true that you can write Vi in Emacs, but you couldn’t ever write Emacs in Vi.

Modes or Modeless

  • Vi has modes. When editing, there’s two main modes - command mode and insert mode. You can only enter commands in command mode, and you can only type text in insert mode. Beginners often forget which mode they’re in, and try to type in command mode, and end up issuing whatever commands they just happened to type. It takes quite a bit of getting used to.
  • Emacs is modeless. You could probably argue that a command mode still exists, but for the most part, if you type text, it appears in your document. Commands are accessed through Ctrl- and Alt- key combinations (though Emacs insists on calling Alt ‘Meta’).

Keystrokes

Both editors aim to save typists from having to move their fingers from the home keys. With most text editors, you have to keep reaching away from the home keys to reach for the arrow keys, or funcion keys. Both Vi and Emacs save you from that.

  • Vi uses single letter commands. Because of the command mode, it doesn’t have to avoid using letters, so moving left can be done with the ‘h’ key, down with ‘j’. ‘0′ will take you to the beginning of a line, and ‘i’ will start inserting text. The only problem comes when you need to switch back from insert mode to command mode, when you have to reach all the way up to the Esc key.
  • Emacs uses combinations of keys - Ctrl-b will go left, Ctrl-n will go down a line. Ctrl-a to go to the beginning of a line. Things that can’t be fitted onto Ctrl- combinations are often on Meta- (Alt-) combinations. Ctrl-Shift- combinations are also used, as are Meta-Shift- combinations. Then there’s commands on combinations of keystrokes, so Ctrl-x followed by Ctrl-s will save, and Ctrl-X followed by Ctrl-c will close Emacs.

Personally, I find reaching for Esc to be a bit irritating in Vi, and no matter how long I use it, I never quite stop trying to type in command mode. I’m getting better, though.

All the key combinations with Emacs can be a bit much, though, and I never could remember if it was Ctrl-x then Ctrl-b or Ctrl-x then b to switch buffers.

My Choice

I very nearly switched completely to Emacs recently, and was really enjoying using PlannerMode for GTD, but hit a bit of a drawback.

I have to switch back and forth a lot, between my editor and my browser, often copying and pasting between the two. That gets confusing when each uses different keystrokes for things as simple as copy and paste.

That drove me away from Emacs, but after trying a few others, and almost settling that I’d have to go back to PSPad, I finally noticed something that I probably should have checked a long time before: Vim does use the Windows standard keystrokes for copying and pasting. Since I like the way it works for most other things, that might just be enough for me to stick with it. I’m using it now to write this, anyway ;)

(Vim? I thought it was called Vi? Yes - Vim is ‘Vi IMproved’ - an extended and modernised version of Vi. Some purists think it’s lost some of what made Vi so great, but for most people, on a reasonably modern machine, it’s much nice to use.)

Anyway, if you’re geek enough to want to use Vi or Emacs, I’m sure you already know what side of the battle you’re on.

3 Responses to “Vi and Emacs”

  1. You might want to also take a look at Cream. Cream is an overlay to VIM that is even easier to use.

  2. Hi Kurt - it was actually trying Cream that sent me back to Vim - it looked like such a good editor, and with such a solid base to work from, it should have been really good.

    I did like it, but it always felt like what it was, to me - a layer on top of a real editor. The odd little flicker as Vim started up, then loaded all the bits and switched itself into Cream mode, the slight flicker at times as it seemed to try to switch modes, then Cream made it switch back.

    It was good, but it just felt wrong to me - certainly worth a try if you don’t fancy the vertical learning curve of Vi, though. Just get the installer with Vim built-in - downloading Cream separately and trying to install it into an existing copy of Vim turned out to be too much for me.

    Oh, and Vi without hjkl makes geeks cry ;)

  3. Arrgghh,

    there is that same old argument again! If you do not like esc, like most users, switch it to e.g. caps lock! Thats one of the most popular tips on vim.org. Btw., those emacs guys tend to do the same: They switch it to be Ctrl. I personally like a simple mapping for insert mode: jj. I hardly ever type this ;) So, if are you still wandering in the shadows, I hope I brought you closer to the light…

Leave a Reply