244 CHAPTER 15 WORKING WITH TEXT FILES (Business web site)
244 CHAPTER 15 WORKING WITH TEXT FILES Using a Command-Line Text Editor A variety of text editors can be used within the shell, but three stand out as being ubiquitous: ed, vi, and Emacs. The first in that list, ed, is by far the simplest. That doesn t necessarily mean that it s simple to use or lacks powerful features, but it just doesn t match the astonishing power of both vi and Emacs. To call viand Emacs simple text editors is to do them a disservice, because both are extremely powerful interactive environments. In particular, Emacs is considered practically an operating system in itself, and some users of Linux treat it as their shell, executing commands and performing everyday tasks, such as reading and sending e-mail from within it. There are entire books written solely about Emacs and vi. Tip A fourth shell-based text editor found on many Linux systems is nano. This offers many word processor-like features that can be helpful if you ve come to Linux from a Windows background. The downside of all the power within Emacs and vi is that both packages can be difficult to learn to use. They re considered idiosyncratic by even their most ardent fans. Both involve the user learning certain unfamiliar concepts, as well as keyboard shortcuts and commands. Although there are debates about which text editor is better and which is best, it s generally agreed that vi offers substantial text-editing power but isn t too all-encompassing. It s also installed by default on Ubuntu. On Ubuntu, Emacs must be installed as an optional extra. Both text editors are normally available on virtually every installation of Linux or Unix. We ll concentrate on using vi here. It s important to understand that there isn t just one program called vi. There are many versions. The original vi program, supplied with Unix, is rarely used nowadays. The most common version of vi is a clone called vim, for vi improved, and this is the version supplied with Ubuntu. However, there are other versions, such as Elvis. Most work in a virtually identical way. Note There s always been a constant flame war between advocates of vi and Emacs, as to which is better. This could be quite a vicious and desperate debate, and the text editor you used was often taken as a measure of your character! Nowadays, the battle between the two camps has softened, and the Emacs versus vi debate is considered an entertaining clich of Linux and Unix use. Declaring online which text editor a user prefers is often followed by a smiley symbol to acknowledge the once-fevered emotions. Understanding vi Modes The key to understanding how vi works is to learn the difference between the various modes. Three modes are important: Command mode, Insert mode, and Command-Line mode.