Cover by Linda Lamb, Elbert Hannah, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Editing Multiple Files

ex commands enable you to switch between multiple files. The advantage of editing multiple files is speed. If you are sharing the system with other users, it takes time to exit and reenter vi for each file you want to edit. Staying in the same editing session and traveling between files is not only faster for access, but you also save abbreviations and command sequences that you have defined (see Chapter 7), and you keep yank buffers so that you can copy text from one file to another.

Invoking vi on Multiple Files

When you first invoke vi, you can name more than one file to edit, and then use ex commands to travel between the files. For example:

$vi file1 file2

edits file1 first. After you have finished editing the first file, the ex command :w writes (saves) file1 and :n calls in the next file (file2).

Suppose you want to edit two files, practice and note:

KeystrokesResults
vi practice note
With a screen editor you can scroll
 the page, move the cursor, delete lines,
 insert characters, and more, while seeing

Open the two files practice and note. The first-named file, practice, appears on your screen. Perform any edits.

:w
 "practice" 6 lines, 328 characters

Save the edited file practice with the ex command w. Press ENTER.

:n
Dear Mr.
 Henshaw:
 Thank you for the prompt . . .

Call in the next file, note, with the ex command n. Press ENTER. Perform any edits.

:x
 "note" 23 lines, 1343 characters

Save the second file, note, and quit the editing session.

Using the Argument ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required