Creating sample files with the vi editor – HP NonStop G-Series User Manual

Page 91

Advertising
background image

Two text editing programs are available with Open System Services: vi and ed. Each has its own
methods of displaying text, as well as its own set of subcommands and usage rules. Your editing
takes place in an edit buffer that you can save or discard.

For more information on vi, see

Appendix A (page 155)

. For more information on ed, see

Appendix B (page 166)

. Commercially available books on vi and ed can also be helpful.

Beginning with the J06.14 and H06.25 RVUs, the Vi IMproved text editor, vim, is available in
the OSS Core Utilities product (T1202). For information about the OSS Core Utilities, see

OSS

Core Utilities User Commands (page 185)

.

Creating Sample Files With the vi Editor

In this subsection you will create three files with the vi text editor. Teaching you how to use the
vi

editor is beyond the scope of this subsection. Instead, the goal is to create, with a minimal set

of commands, files that can be used for working through the examples in this guide.

To start the vi editor, type vi followed by a filename, and press Return. A vi window opens.
The vi editor has an insert mode for adding and changing text. To enter insert mode, you type
the letter i (insert) or a (append); you do not need to press Return. The letter does not appear on
the screen. To exit insert mode, press the Escape key.

To exit the vi editor, type a : (colon) followed by the letter q and press Return: :q<Return>. If
you have made changes to the file, vi does not let you exit until you either save the changes or
discard them. To save changes and exit vi, type :wq. To discard the changes and exit vi, type
:q!

. You cannot exit vi while you are in insert mode. Exit insert mode before typing :wq or :q!.

Perform the following steps to create three sample files (file1, file2, and file3), which will
be used in the subsections that follow.
1.

Start the vi program by typing the command vi followed by the name of a new file (file1),
and then press Return:

$ vi file1

This is a new file, so the system responds by putting your cursor at the top of a screen that
looks like the following:

~
~
~
~
~
~
"file1" [New file]

Note the blank lines on your screen that begin with a ~ (tilde). These tildes indicate the lines
that contain no text. Because you have not entered any text, all lines begin with a tilde.

2.

Specify that you want to add text to the new file by typing the letter i (insert text). The system
does not display the i that you type.

3.

After typing the letter i, enter the following text:

You start the vi program by entering the command vi,
optionally followed by the name of a new or existing file.
~
~
~
~
~
~
"file1" [New file]

If you make mistakes and wish to correct them before moving to the next line, move the cursor
backwards to the error and then retype the text.

That is all you need to enter for the text of file1.

Working With Files

91

Advertising
This manual is related to the following products: