Chapter 11. The vi EditorContents:
Review of vi Operations vi is the classic screen-editing program for Unix. A number of enhanced versions exist, including nvi, vim, vile, and elvis. On Linux, the vi command is usually a link to one of these programs. vi is based on an older line editor called ex. Powerful editing capabilities can be invoked within vi by pressing the colon (:), entering an ex command, and pressing the Return key. Furthermore, you can place ex commands in a startup file called ~/.exrc, which vi reads at the beginning of your editing session. Because ex commands are still an important part of vi, they also are described in this chapter. On Linux, ex is sometimes called hex. This chapter, which essentially covers standard vi but reflects nvi extensions, presents the following topics:
For more information, see the O'Reilly book Learning the vi Editor by Linda Lamb and Arnold Robbins. 11.1. Review of vi OperationsThis section provides a review of the following:
11.1.1. Command ModeOnce the file is opened, you are in command mode. From command mode, you can:
11.1.2. Insert ModeIn insert mode, you can enter new text in the file. Press the Esc or Ctrl-[ keys to exit insert mode and return to command mode. The following commands invoke insert mode:
11.1.3. Syntax of vi CommandsIn vi, commands have the following general form: [n] operator [m] object The basic editing operators are:
If the current line is the object of the operation, then the operator is the same as the object: cc, dd, yy. Otherwise, the editing operators act on objects specified by cursor-movement commands or pattern-matching commands. n and m are the number of times the operation is performed or the number of objects the operation is performed on. If both n and m are specified, the effect is n × m. An object can represent any of the following text blocks:
11.1.3.1. Examples
11.1.4. Status-Line CommandsMost commands are not echoed on the screen as you input them. However, the status line at the bottom of the screen is used to echo input for the following commands:
Commands that are input on the status line must be entered by pressing the Return key. In addition, error messages and output from the Ctrl-G command are displayed on the status line. Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|