UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
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:
Switch to insert mode and make additions or modifications to the file.
Switch to command mode to manipulate, move, save, or exit the file.
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.
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 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.
Insert mode --In this mode, text is placed in the buffer until a write command is issued. No commands are recognized in this mode. To leave the input mode type a period ( .) on a line by itself followed by the Enter key.
Command mode --In command mode, single-letter commands are preceded by zero, one, or two addresses. These addresses specify one or more lines in the buffer that the command uses. Only one command per line is allowed.
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.
Insert mode --In this mode, keys that the user types are displayed on the screen (except for the Esc key). This mode is also known as the input mode.
Command mode --In this mode, every key that the user types is interpreted as a command. Some keys do not have functions associated with them. If one of these keys is entered, nothing happens to the text, but the editor might beep. As you enter commands in this mode, you will not see an echo of your keystroke, however you will see the results of the command from that keystroke.
Last line mode --This mode enables you to edit and issue a line of commands to the editor or to the system. The input line appears at the bottom of screen or window when you type a colon ( :). In this mode, you see the keystrokes echoed back onto the screen, unlike in the command mode. The last line mode is also referred to by many people as the command line mode or even the command mode.
UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.