Vi(m): The One True Text Editor

And a denunciation of that other text "editor" Emacs

Introduction

Ok, so I'm probably biased on this subject. Harvard's computer science department teaches Vi as its standard text editor; I never was introduced to Emacs until a few months later, and not in the most pleasant of ways.

The story goes like this: I was running some backgrounded processes on the university Unix servers, and I accidentally started Emacs from the command prompt. I then spent the next hour trying to quit. Unsuccessfully. The most I could figure out was how to play Go-Moku against the computer (and lose to it every time). Eventually I just killed off the terminal.

Looking back on that, I probably should have just logged in from somewhere else and killed the process. Still, though, this episode has scarred my memory for life.

What is a Text Editor?

If you already know what Vi, Emacs, and text editors in general are, you can skip this section.

Vi and its improved descendant Vim are text editors, programs whose purpose is to edit plain text files (like Notepad, for all you users of that other operating system). Vi is probably the oldest visual text editor around, but it is not the only one; others include Emacs and Pico for Unix, TextPad for Windows, and BBEdit for the Macintosh.

It would seem at first glance that the idea of a simple text editor is a pretty silly idea--after all, how much can you really do with just plain text without formatting or fonts or anything? But a good text editor does more than just edit files: syntax highlighting (coloring of special keywords and phrases for some programming language) and automatic indentation can have dramatic impact on productivity, and powerful text processing tools, the simplest being search and replace, can turn a long and repetitious session of editing into a matter of a few keystrokes.

And the value of plain text files themselves is not to be underestimated either. After all, even documents with the most complex formatting are, in their underlying form, nothing more than plain files that can be edited with a text editor (yes, a good text editor should be able to read binary files). And plain, readable text files form the backbone of much of the data your computer works with; view the source of any web page to see the proof. In particular, the Unix operating system runs based on configurations set up in numerous text files, such as the /etc/passwd file.

Why Vi?

The above notwithstanding, there are a number of objective reasons (at least to me) why Vi is superior to that spawn of the devil.

There is no doubt that Emacs is a highly configurable, highly functional program. One can do just about everything from talking to an AI psychologist to checking e-mail from Emacs. These are nice, but features don't matter when you're pressing Alt and Ctrl on every other keystroke. The famous aphorism that sums it all up is:

Emacs would be a great operating system, if only it came with a text editor.

Vi vs. Vim

Vim is a greatly improved version of the Vi standard, adding features such as fully configurable color syntax highlighting, multiple windows, and a nice GUI for multiple platforms. Vim is by far the most popular text editor among Linux users. It is excellent for programming in just about any language (there are syntax files for 341 languages) and also for just writing nice documents. I'm writing this HTML page in Vim; in fact, every page on this website has been either written or heavily modified using it.

A Word of Warning

One thing to keep in mind: once you use Vi/Vim on a regular basis, you will find that other word processors just don't cut it. You open up Microsoft Word, start typing your paper, and find yourself pressing Escape every few words. You try to save and type :w into your document. You type long strings of "jjjjj" when you're trying to scroll.

Yes, it will consume your life entirely. You will never be able to use another text editor again. Good for you.

Are you ready to be initiated? Begin the tutorial!