BELUG > vi > previous

Working With Multiple Files

It is easy to insert text into an open file from another file. All that is necessary is to move the cursor to the location where you want the text inserted, then type

:r filename

where "filename" is the name of the file to insert.

For example, if you want to copy the contents of the file "peach" into the file "fruit," you would first position the cursor to the desired line in "fruit" and then type

:r peach

Notice that this operation causes no change to the file "peach."

You can also append text from the currently open file to any other file. This is accomplished using the :w (colon + "w") command followed without a space by >>. For example, to append the contents of a currently open file named "pear" to the file named "apple," type

:w>> apple

At times it can be convenient to open multiple files simultaneously. This is efficiently accomplished by just listing all of the files to be opened after the vi command. For example, to simultaneously open files about three kinds of fruit, type:

vi apple pear orange

This allows you to edit "apple" first. After saving "apple," typing :n calls up "pear" for editing.

If you want to simultaneously open all files in the current directory, just type vi * (vi + space + asterisk).