Deleting multiple words, Changing text, Undoing a command – HP NonStop G-Series User Manual

Page 160: Finishing your edit session, Using advanced techniques

Advertising
background image

general form to move the cursor in larger steps. For example, to move the cursor forward five
words, enter:

5w

Deleting Multiple Words

Using the general form described earlier, you can delete the last five words in my.file by moving
to the beginning of the last line and entering:

5dw

Note that it takes five words to delete the whole line, rather than four. This is because the trailing
period counts as a word.
The dd command deletes an entire line of text. The dd command can also be used with a number
to delete multiple lines.

Changing Text

The command for changing text is c, which can be used to combine the actions of deleting and
returning to input mode. The form for the c command follows the general form for the d command.
To change the text “new text” to “almost new demo”, you can move the cursor to the first character
in the word new. Then, enter the command:

2cw

The text will not immediately disappear. Instead, a $ (dollar sign) is placed at the end of the change
range (the last t in “text”), and you are placed in input mode. The text you type will overwrite the
existing text up to the dollar sign and then extend the text as needed. Enter the new text by typing:

almost new demo<Esc>

Both the c and d commands can be used together with any of the motion commands to give you
more editing power.

Undoing a Command

If you make a change and then realize it was in error, you may still be able to correct it. The u
command undoes the last command entered. Try undoing the last command by typing:

u

The string “almost new demo” will be changed back to “new text”.

Finishing Your Edit Session

After you finish making changes, you need to save those changes and quit vi. To save your
changes and quit vi, enter:

:wq<Return>

Note that the format of this command is much different than other vi commands. That is because
it is not a vi command: it is an ex command. When you press :, it appears at the bottom of the
screen. The : begins all ex commands from within vi. The wq command writes the file and quits
the editing session. You need to press Return after the command to signify to ex that you are
finished entering the command. You will learn more about ex commands later in this appendix.
To quit vi without saving your changes, enter:

:q!<Return>

The following subsections present advanced techniques that improve productivity and allow you
to customize your environment.

Using Advanced Techniques

This subsection will show you how to search for strings, move text, and copy text. As you deal with
larger documents, all these tasks increase your ability to work efficiently.
Under

“Other vi Features” (page 162)

is a short list of other advanced features of vi.

160 The vi Editor

Advertising
This manual is related to the following products: