Other vi features, Using the underlying ex commands, Making substitutions – HP NonStop G-Series User Manual

Page 162

Advertising
background image

Other vi Features

You may want to try some of the other features of vi. The reference page for vi lists its available
commands. You may want to pay particular attention to the following:

Joins the following line to the current line.

J

Repeats the last command.

.

Substitutes the current character with the following entered text.

s

Deletes the current character.

x

Changes the alphabetic case of the current character.

~

Executes an OSS command on the current line of text and replaces the text with the output.

!!

Refreshes the screen when problems with the screen display features of vi occur. Anytime your
screen is displaying confusing output, press Ctrl-l.

Ctrl-l

Using the Underlying ex Commands

The vi screen editor is based on the ex line editor. With the ex line editor you can make global
changes to files. Commands of ex can be executed from within vi by using the vi command :.
The : command causes ex to prompt for a single command line at the bottom of the screen with
a :. Finish each ex command by pressing Return. After each ex command finishes, ex terminates
and returns you to vi. You can enter ex more permanently with the vi command Q. This command
turns processing over to ex until you explicitly return to vi. This often happens accidentally. If it
should happen to you, return to vi by typing vi at the : (colon) prompt and pressing Return, as
follows:

:vi<Return>

An ex command acts on a block of lines in your text file according to the following general syntax:

:address1,address2 command

command

, along with any of its arguments, acts on the lines between and including address1

and address2. If only one address is specified, the command acts only on the specified line. If
no address is specified, the command acts only on the current line. Addresses can be specified in
a number of ways.
Some of the more common address specifications are the following:

Specifies an address by absolute line number.

line_number

Specifies the next line that contains the pattern.

/pattern/

Specifies the line that the cursor is on.

.

Specifies the last line of the file.

$

Specifies a relative offset from the addressed line.

address

±lines

Specifies all the lines in the file and is used once in place of both addresses.

%

The following subsections show some useful ex commands and some of the customization features
offered by ex. For a more detailed list of commands, see the ex(1) reference page either online
or in the Open System Services Shell and Utilities Reference Manual.

Making Substitutions

A common ex task is the global substitution of one word or phrase for another. You can do this
with the s command. If you have closed the file my.file, reopen it.
To change every occurrence of “is” to “was”, use the following command:

:%s/is/was/g<Return>

162

The vi Editor

Advertising
This manual is related to the following products: