5.5 Editing Multiple Filesex commands enable you to switch between multiple files. The advantage to 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, 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 FilesWhen 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: $ edits 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 Using the Argument List
ex
actually lets you do more than just
move to the next file in the argument list with
The 5.5.3 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 : 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 The following command is also useful. It discards your edits and returns to the last saved version of the current file: :e! In contrast to the :w practice.new Since :w %.new 5.5.4 Switching Files from vi
[ctrl-^]
Since switching back to the previous file is something that
tends to happen a lot, you don't have to move to the ex
command line to do it. The vi
command 5.5.5 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 For example:
would yank (copy) lines 160 through 224 into buffer :pu a to put the contents of buffer | ||||||||||||||||||||||||||||||||
|