5.5 Editing Multiple Filesex commands enable you to switch between multiple files. The advantage to editing multiple files is speed. When 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, Advanced Editing , and you keep yank buffers so that you can copy text from one file to another. 5.5.1 Invoking vi on Multiple Files oneWhen you first invoke vi , you can name more than one file to edit, and then use ex commands to travel between the files.
$
invokes
file1
first.
After you have finished editing the first file,
the
ex
command Suppose you want to edit two files, practice and note .
5.5.2 Calling In New Files
You don't have to call in multiple files at the beginning of your
editing session.
You can switch to another file at any time with the
ex
command
:e filename Suppose you are editing the file practice and want to edit the file letter , then return to practice .
vi
"remembers" two filenames at a time as the current and
alternate filenames.
These can be referred to by the symbols
If you have not first saved the current file,
vi
will not allow
you to switch files with
For example, if after making some edits to
letter
,
you wanted to discard the edits and return to
practice
,
you could type
:e! is also useful. It discards your edits and returns to the last saved version of the current file.
In contrast to the
:w practice.new
Since
:w %.new 5.5.3 Edits Between Files
When you give a yank buffer a one-letter name,
you have a convenient way to move text from one file to
another.
Named buffers are not cleared when a new file is loaded into
the
vi
buffer with the The following example illustrates how to transfer text from one file to another.
Another way to move text from one file to another is to use the
ex
commands
would yank (copy) lines 160 through 224 into buffer a.
Next you would move with
:pu a |
|