UNIX Hints & Hacks

ContentsIndex

Chapter 8: Editors

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

8.1 The Anatomy of ed & vi

 

8.5 Abbreviating vi Commands

 

 

8.2 The Six Steps to ed

 

8.6 Creating Macros

 

8.10 Edit, Run, and Edit Again

 

8.3 Six Simple Steps to vi

 

8.7 Search and Replace

 

8.11 Reading STDOUT into vi

 

8.4 Configuring vi Parameters

 

8.8 Other Places to Use vi

 

8.12 Using vi when tmp Is Full

 

 

Chapter 8
Editors

This chapter does not provide an in-depth discussion of the ed and vi editors. There are already books specific to that subject, and there's information in every introductory UNIX book on the market. This chapter concentrates on telling you why you should use these editors and how you can best use them as an administrator to take full advantage of their capabilities to make your job a little easier.

It is often said that if you can drive a car with manual transmission then you can drive any car on the road. The same can be said about the oldest editors of UNIX. There are other editors that are freely available on the Internet and some user-friendly GUI editors are supplied by vendors as part of their UNIX flavors. So why cover these two editors in this book? Administrators should know all this already. The reality is that there are UNIX administrators with two or more years' experience who have never really used these editors.

If you want to be a guru, here's a hint: You have to learn the tools of the trade. Don't be surprised if you are even asked questions in a job interview pertaining to editors and asked how fluent you are in them. If you don't know the basics, you might not get the job. You might even be asked what keys, other than the arrow keys, move the cursor around. You would be amazed at the number of administrators who don't know the right answer. Some interviewers believe this can help determine the level of experience or devotion to the UNIX operating system. I have found that a lot of administrators who have learned UNIX since 1989 use the arrows. If they have to think about the letters ( h, j, k, and l) they probably haven't been using UNIX for more than seven years.

As much as you might hate these editors for their cryptic command structure or because you cannot use a mouse or even the arrow keys sometimes, learning the minimum requirements for the editors will be enough to get you by. All you have to do is learn the six basic steps for editing:

Mastering these six simple steps takes only 30 minutes for each editor, if you sit down and take the time to learn. After you are hooked, you might not accept any substitutes.

8.1 The Anatomy of ed & vi

8.1.1 Description

8.1.1 Description

If you want to know UNIX, you've got to know ed and vi. No matter what the flavor of UNIX, these two editors are always there for you. Some editors other than ed and vi might be excellent for everyday use, but when push comes to shove and there isn't enough memory, disk space, or the system is in bad shape, you can usually still count on ed or vi to save the day.

Editors can be installed anywhere on your system--in /usr, /usr/local, /opt, or some partition other than the root partition. The ed editor, however, remains installed in the root partition and is part of the operating system when you need to boot into miniroot. So you see, when a worst-case scenario takes place, you will still have access to ed.

The ed and vi editors are made up of several parts that enable you to navigate in and manipulate the system files in a pinch. Knowing the basic parts helps you to better understand these editors.

ed

ed is a standard text editor. No frills; it is as basic as they get. Do you need to learn this editor? Yes! You don't need to know everything, just the basics. Startup, adding, deleting, saving, and exiting are all you should need. The ed editor is used primarily in extreme emergencies when all other editors are inaccessible. Can this happen? Yes! If the system crashes hard enough, this definitely can happen.

When you use ed, remember that only one command at a time can appear on a line. ed runs in two modes: insert and command.

vi

vi is actually the visual part of the text editor ex, which in turn is a superset of the ed editor. Although a lot of the vi commands originate from ex, I will still reference vi for these commands. For those who are not aware of this, the vi editor was originally designed with three modes: insert, command, and last line. Don't be confused about the third mode. Many admins say there are only two modes: insert and command. The last line mode is sometimes considered part of the command mode, because it is used for entering various commands.

UNIX Hints & Hacks

ContentsIndex

Chapter 8: Editors

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

8.1 The Anatomy of ed & vi

 

8.5 Abbreviating vi Commands

 

 

8.2 The Six Steps to ed

 

8.6 Creating Macros

 

8.10 Edit, Run, and Edit Again

 

8.3 Six Simple Steps to vi

 

8.7 Search and Replace

 

8.11 Reading STDOUT into vi

 

8.4 Configuring vi Parameters

 

8.8 Other Places to Use vi

 

8.12 Using vi when tmp Is Full

 

 

© Copyright Macmillan USA. All rights reserved.