OpenWindows Advanced User's Guide

6.9 Editing Multiple Files

vi allows you to edit multiple files. For example, to edit the file orwell while you are editing paint:

  1. First, save your current work in paint. Type :w and press Return.

  2. To edit orwell, type :n orwell and press Return.

  3. Make editing changes to orwell and save your work.

  4. When you are finished working with orwell and have saved your work, you have three choices:

    • Exit vi. Type :q and press Return.

    • Return to paint. Type :n # and press Return.

    • Swap back and forth between two files with the command :n #.

6.9.1 Editing a Series of Files

To edit a series of files, list the file names after the vi command when you start vi from the command prompt:

$ vi paint orwell

The files appear in the order in which they are listed. First paint appears. When you finish editing paint, type :n to go on to the next file, orwell. To go on to the next file without saving changes in the current file, type :n! instead of :n.

If you have a series of files with related names (for example, test1, test2, test3), you can use wildcard characters to specify a group of files:

$ vi test*

The files will appear for editing in alphabetical order by name.

6.9.2 Copying Lines Between Files

To copy lines from one file to another, do the following:

  1. Edit the first file.

  2. Save the desired lines in named buffers, using the yank command. For example, to save 10 lines in buffer a, type a10Y.

  3. Without exiting vi, edit the next file (orwell in this example):

    :n orwell
    

  4. Add the lines from the first file with the put command. For example, to put the contents of buffer a below the current cursor position, type ap.

Remember that the contents of all named buffers are lost whenever you exit vi. Don't use the quit (:q) command until you have finished any operations involving named buffers.