Review of vi Operations
vi Command-Line Options
ex Command-Line Options
Movement Commands
Edit Commands
Saving and Exiting
Accessing Multiple Files
Interacting with the Shell
Macros
Miscellaneous Commands
Alphabetical List of Keys in Command Mode
Syntax of ex Commands
Alphabetical Summary of ex Commands
vi Configuration
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:
vi command-line options
ex command-line options
Movement commands
Edit commands
Saving and exiting
Accessing multiple files
Interacting with the shell
Macros
Miscellaneous commands
Alphabetical list of keys in command mode
Syntax of ex commands
Alphabetical summary of ex commands
vi configuration (setting options at startup)
For more information, see the O'Reilly book Learning the vi Editor by Linda Lamb and Arnold Robbins.
This section provides a review of the following:
Command-line options
vi modes
Syntax of vi commands
Status-line commands
Once the file is opened, you are in command mode. From command mode, you can:
Invoke insert mode
Issue editing commands
Move the cursor to a different position in the file
Invoke ex commands
Invoke a Linux shell
Save or exit the current version of the file
In 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:
Append after cursor
Append at end-of-line
Begin change operation (must be followed by a movement command)
Change to end-of-line
Insert before cursor
Insert at beginning of line
Open a line below current line
Open a line above current line
Begin overwriting text
Substitute a character
Substitute entire line
In vi, commands have the following general form:
[n] operator [m] object
The basic editing operators are:
Begin a change
Begin a deletion
Begin a yank (or copy)
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:
Includes characters up to a space or punctuation mark. A capitalized object is a variant form that recognizes only blank spaces.
Extends to ., !, ? followed by two spaces.
Extends to next blank line or nroff/troff paragraph macro (defined by para= option).
Extends to next nroff/troff section heading (defined by sect= option).
Change the next two words
Delete up to next paragraph
Delete back to beginning of line
Copy the next five lines into temporary buffer (for future pasting)
Copy up to the next section into temporary buffer (for future pasting)
Most 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:
Search forward for a pattern
Search backward for a pattern
Invoke an ex command
Pipe the text indicated by a subsequent movement command through the following shell command, and replace the text with the output of the shell command
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.
This HTML Help has been published using the chm2web software. |