Emacs and Vi

Few subjects ignite such heated controversy among geeks as their favorite text editor. Just yell ``vi SUX!'' in a busy Linux newsgroup and watch how long the debate rages. This behavior should probably be outlawed because it's the equivalent of yelling ``fire'' in a crowded theater.

There are many many editors you have to choose from. Two of the most popular are vi and emacs.

The vi Editor

vi is a pure example of the Unix philosophy of using a single small program to accomplish a specific task. It is the traditional editor that is still found on nearly every Unix workstation, and despite its non-intuitive command set, it is quite powerful once you learn how to use it. Various vi clones abound, such as elvis, vim, and vile, but a rose by any other name is still a rose.

This editor has two basic modes of operation: insert and edit. The default mode is edit, and in order to insert text you can hit the ``i'' key. Hit the ESC key to return to edit mode.

The edit mode is made for speed. Most commands are one or two keystrokes. You won't find multi-column displays or tables in this little editor, but vi was built to be extensible. You can easily issue shell commands or call macros from vi's command line. Unix is full of small programs that do a single task that can be called from another program that does a single task. vi is famous for being extremely flexible and scalable like this.

One of the biggest strengths of vi is that it doesn't require many system resources at all. So if you fry your system and you're only able to get a crippled system to boot, vi will still run just fine.

But vi doesn't stop there. Many old-time Unix geezers still use the little editor to edit large files or even write books. If memory serves, Matt Welsh wrote several of his books for the Linux Documentation Projects just using vi and LaTeX. The majority of the developers at RedHat software seem to prefer vi and clones, according to the consensus at the last editor war that took place on the red-hat mailing list.

The only thing that puts new vi users off is the cryptic command set. My best advice there is to get a cheat sheet and keep it handy. Many exist. And once you have learned those 30 or so most often used editing commands, you'll be surprised at how amazingly productive you can be with such a tiny little tool. It's like a pen knife that you always carry with you because it works for everything from peeling apples to unscrewing the back of your computer.

Emacs the Magnificent

If vi is a small pen knive, emacs is the mother of all Swiss Army knives. Unlike vi which relies on external programs, emacs has numerous built-in tools. In fact, it has its own programming language called elisp, a variation of common lisp. Using this language, people have built many ``modes'' for emacs--newsreader, mail reader, directory editor, command shell, compiler, debugger, documentation reader, outline generator, web browser, gopher client, and many more. In a way, emacs seems like a rebellion against the traditional Unix philosophy of ``one task, one tool.''

But emacs is actually a case study of another Unix maxim: small and specific tools should be capable of interfacing together. This is what emacs does. Each of the many ``blades'' on its Swiss Army knife collection of tools is its own small program that was designed to work inside of the emacs environment. But emacs doesn't have to have all these little tools on it. You can compile it with many different options according to your own preferences, from elaborate and broad applications to narrow and specific specialties. For example, one version of emacs called emacs nox occupies a much smaller niche on your hard drive than, say, xemacs, which must use many X Windows resources. In fact, GNU emacs and xemacs are two almost radically different implementations of the same software. One has been around forever, and the other, xemacs, was written with many attractive visual enhancements for the X Windows environment, including a button bar with pretty icons on it and object oriented features that rival the popular ``visual'' programming environments on Windows environments.

The saying among emacs fans is--``emacs: It's not just an editor, it's a way of life!'' That could also be because it takes your whole life to figure out how to use it. Just joking. What they really mean is you could spend your whole life inside emacs without ever having to come out and run an external application.

Actually, like any application, you learn first and best what you need most. If you use emacs as your login shell, your mailer, your newsreader, your file manager, etc., you'll be an emacs guru before you know it. If you simply want to use it for your program editor, that's fine too. Either way, you'll become familiar with the unique features it can offer just to you.

So What Should I Use?

Either, both, neither. I haven't even talked about the myriad alternative editors like joe, jed, nedit, xcoral, or many others. Many people use one of these without ever stepping foot near vi or emacs.

I think you would be best served by learning both, however. Not only will you be better equipped, but you'll reduce your odds of ever being bored!

©David S. Jackson
Mon Jul 14 20:51:38 PDT 1997