More vi Magic
need to, we can also edit multiple files. This is done like this:
vi file1 file2 file3
Once we are editing, we can switch between files with :n for the next file and :p for the
Keep in mind that the file names do not wrap around. In other words, if we keep pressing
:n and get to file3, doing
it again does not wrap around and bring me to file1. If we know the name of the file,
we can jump directly there, with the
ex-mode edit command, as in
The ability to edit multiple files has another advantage. Do you remember those numbered and named buffers?
They are assigned for a single instance of vi, not on a per-file basis. Therefore, you can delete or yank text
from one file, switch to the next and then insert it. This is a crude but effective cut and paste mechanism between files.
You can specify line numbers to set your position within a file. If you switch to editing another file (using :n or :r),
or reload an original file (using :rew!), the contents of the deletion buffers are preserved so that you can cut and paste
between files. The contents of all buffers are lost, however, when you quit vi.