5.3 Saving and Exiting Files
You have learned the
vi
command
vi protects existing files and your edits in the buffer. For example, if you want to write your buffer to an existing file, vi gives you a warning. Likewise, if you have invoked vi on a file, made edits, and want to quit without saving the edits, vi gives you an error message such as:
No write since last change.
These warnings can prevent costly mistakes, but sometimes you want to
proceed with the command anyway.
An exclamation point (
:w! :q!
5.3.1 Renaming the Buffer
You can also use Suppose you have a file practice , containing 600 lines. You open the file and make extensive edits. You want to quit but save both the old version of practice and your new edits for comparison. To save the edited buffer in a file called practice.new , give the command:
:
Your old version, in the file
practice
, remains unchanged
(provided that you didn't previously use 5.3.2 Saving Part of a FileWhile editing, you will sometimes want to save just part of your file as a separate, new file. For example, you might have entered formatting codes and text that you want to use as a header for several files.
You can combine
ex
line addressing with the write command,
5.3.3 Appending to a Saved File
You can use the UNIX redirect and append operator (
then:
newfile would contain lines 1-10 and from line 340 to the end of the buffer. |
|