Moving within the file, Entering new text, Moving within the file entering new text – HP NonStop G-Series User Manual

Page 158

Advertising
background image

You should see the text of your sample file at the top of the screen and a number of lines following
it that begin with a ~ (tilde). The lines beginning with tildes are the remaining blank lines on your
screen. The line at the very bottom of the screen shows the name of the file, the number of lines in
the file, and the number of characters.
To quit vi at this point, enter:

:q

Exiting vi is described in

“Finishing Your Edit Session” (page 160)

.

Moving Within the File

If you have closed my.file, reopen it as described in the previous subsection. The text cursor
should be on the first character of the file: the Y in “You.”
When you start up vi, it is in command mode. In command mode, the characters you enter are
treated as commands rather than as text input to the file. You can use the keys h, j, k, and l to
move the cursor one character at a time to the left, down, up, and right, respectively. Try moving
the cursor to the first letter of the word “experiment” by typing:

lllj

Note that, if your keyboard is equipped with arrow keys, you might be able to use them to move
left, right, up, or down. However, using the h, j, k, and l keys allows you to keep your fingers on
the main section of the keyboard for faster typing. Also note that there is no need to press the
Return key after most vi commands. When you are in command mode, pressing Return moves
the cursor to the first character of the next line.
You can also move the cursor by whole-word boundaries. The w command moves to the beginning
of the next word. Move the cursor to the beginning of the word “with” by typing:

w

You can also use the b command to move back to the next beginning of a word. For example,
move to the beginning of the word “experiment” again by typing:

b

Now see what happens when you do not use the b command from the beginning of a word, by
typing:

llllb

The cursor returns to the beginning of the word “experiment.”
The cursor wraps to the next or previous text line when appropriate. Try moving the cursor to the
beginning of the word “text” by typing:

bbb

Other movement commands are described below:

The 0 and $ commands move to the beginning and end of the current text line.

The ) and ( commands move to the beginning of the next and previous sentences.

The } and { commands move to the beginning of the next and previous paragraphs.

In larger files, you can move the cursor by screenfuls and scroll the screen at the same time by
pressing Ctrl-f and Ctrl-b. Ctrl-f moves the cursor to scroll the text one screen forward, and Ctrl-b
moves the cursor to scroll the text one screen backward.
The vi editor has additional cursor movements that are described in advanced books on vi and
in the vi(1) reference page either online or in the Open System Services Shell and Utilities
Reference Manual
.

Entering New Text

To enter new text into a file, you must change to input mode. In input mode, the characters you
type are added directly to the text of the file. You can always get out of input mode and back into
command mode by pressing the Esc key. If you ever lose track of which mode you are in, press
Esc to get back into command mode. Your system may be configured so that you hear a bell when
you press Esc while in command mode.

158

The vi Editor

Advertising
This manual is related to the following products: