Text Editors

One of the central tenets of unix philosophy is the primacy of plain text, especially human-readable and line-oriented plain text. Where other systems would have databases structured for machine-readability, or binary-formatted records, unix has text. It means programs have to do more parsing and formatting of text, but it means there is a language in common, and the human isn’t left out. The flip side of that coin is that the tool that gives the human the ability to edit text files is not just a sometimes-useful tool—it is one of the most important aspects of how it feels to use your unix system.

Naturally, people develop very strong feelings about their text editors, and some of the most vicious Internet flame wars have burned for years fueled by the subject of what text editor is ‘best’. What you find ‘best’ is for you to discover, but you will not be a truly competent unix user (or, indeed, programmer) until you have mastered a hacker’s text editor.

There are two main camps: vi and emacs.

vi

The vi editor is modal; there is, for example, a command mode in which almost every button on your keyboard issues some kind of text-editing command. Entering text, which is what many people would expect those buttons to do, is also a mode. For those inexperienced with vi, the fact that firing it up and typing does not put letters into your text file is often offensive. However, there is method to it: when you are typing text, there is nothing else going on, and the only special character is the one that says you’re done typing for now. And when you’re giving commands, there’s no need for holding down control and shift at the same time: a single keypress can accomplish a great deal.

This camp comes out of Berkeley unix culture. Dennis Ritchie (the ‘R’ of K&R) wrote an editor named ed, which introduced the use of regular expressions for text editing. That original ed has been standardized from the beginning as an essential utility to be installed on any system calling itself ‘unix’. It is fairly rudimentary, however, so Bill Joy wrote an extended version called ex. When it became more common to use screens than line-printed terminals, he added a visual mode called vi. Most people these days use an even further improved version by Bram Moolenaar called vim, for ‘vi improved’.

To learn vi, just run vimtutor and follow along.

emacs

The emacs editor is programmable; it is written in its own programming language, emacs-lisp, and you can live-edit emacs-lisp scripts to change the editor’s behavior from within it. This extreme programmability and flexibility have led to it expanding from a text editor into a whole environment, even a way of life, for those who are into it. Most of the time, a user of emacs can ignore lisp programming, however; most commands are issued by holding down control and sometimes other modifier keys, sometimes in sequences.

This camp comes out of MIT hacker culture. There was originally TECO, short for ‘Text [or Tape] Editor and Corrector’, which was a text-editing programming language used to fix programs for the PDP-1. A set of Editor MACroS (emacs) written in TECO by David A Moon and Guy L Steele Jr came to be its own editor that became popular throughout hacker culture. When Richard Stallman created the Gnu project after the collapse of the original MIT hacker culture, the first program he wrote for his new operating system was a version of emacs, which is now the most famous and widely-used version. (In fact, ITS emacs on which he based his work was in turn based on Stallman’s own pre-ITS emacs.)

To learn emacs, just run emacs, then type ‘C-h t’, i.e. press and hold control, then press ‘h’ (for ‘help’) and release both, then press ‘t’ (for ‘tutorial’).

Other editors

There are other editors that are widely used. In particular, the evolution of ed, the ‘standard editor’, took a different branch in the Plan 9 operating system, where Rob Pike wrote sam and acme. If you’re interested in unix tools, take a look at Plan 9 tools such as sam and acme, which have been ported so it is possible to run them on Linux.

Some editors have been written to be particularly easy for newcomers to pick up quickly, such as pico and its improved clone nano, or Gnu moe. If you don’t have the extra attention to put into mastering vi or emacs yet, one of these might be a good way to work.

If you’re curious about my opinion, here it is. I use vim, but I have also used plain-old non-improved vi, and even done significant editing in ed, the standard editor. For a while, to see what the fuss was about, I used emacs. It was also good. Switching back and forth, keeping up with both skillsets, took too much effort, so I settled on vi for the sake of familiarity. It’s what my fingers know. It’s what I recommend. But the reason the silly war continues is that all the sides are right: all that matters is that you find a powerful, configurable text editor that you can settle into and use until it is second nature.

You have attempted of activities on this page