
The ECN No Name Newsletter is no longer being published. This is an archived issue.
[previous article] [next article]The VI editor provides an advanced feature which allows a user to invoke the editor and then edit multiple files by use of the ":e" (edit) command. This ability to access multiple files without leaving the editor permits a user to look up information in another file without exiting the editor. Additionally, because files are opened within the same editor invocation they can share the same named buffers, thereby making the transfer of text possible between the files. The example on the next page demonstrates how two lines can be "yanked" from the file oranges, placed into a named buffer "k", and then "put" into the file apples.
When VI is invoked, a work area called a buffer is created for editing purposes. It is into this work space that a copy of a specified disk file is placed. The editor permits only one file copy in this buffer space at a time. Thus after making changes to a file (delete, add, or change), you must inform the editor what you wish done to the current buffer contents before you will be permitted to bring another file into this space. You do this by use of the ":w" (write current buffer contents to opened file), ":e! newfile" (toss current buffer contents, no update to opened file, and place a copy of newly called file in buffer), or ":quit!" (exit editor and toss buffer and buffer contents). The editor is smart enough to know that if all you have done is copy or read from a file, it can dispose of the unneeded buffer copy without further instructions from you when a new file is called.
When you have two files open, VI permits toggling between files by use of ":e#". This works because whenever VI sees the character "#" used in a command where a filename is expected, it substitutes the "#" with the name of the previous file. For example if you had been in apples then opened oranges, the command ":e#" would return you to where you were in the apples file. Repeat ":e#" and you would be back in oranges.
A figure is presented at this point in this newsletter and the following points refer to this figure.
Another method to "cut" and "paste" between files is to use the mark command (m) in conjunction with named buffers ( '' ). Move the cursor to the first line you wish to copy from oranges and type "ma" (m to mark the line and a to specify which mark). Next move the cursor to the last line you wish to copy and type " ''zy'a". This command tells VI to open up ''z (buffer named z) and y (yank) a copy of all the lines from the line marked 'a to the current line and place them in the aforementioned buffer. Return to apples with ":e#" and proceed to paste the contents of ''z by moving to the desired location and p (put) the buffer contents by typing " ''zp ".