Solaris Advanced User's Guide

Ending a Session

When you edit a file in vi, your changes are not made directly to the file. Instead, they are applied to a copy of the file that vi creates in a temporary memory space that is called the buffer. The permanent disk copy of the file is modified only when you write (save) the contents of the buffer.

This arrangement is both positive and negative. A positive feature is that you can quit a file and discard all the changes that you have made during an editing session, leaving the disk copy intact. The negative feature is that you could lose the (unsaved) contents of the work buffer if the system crashes. People on remote terminals that are connected by phone lines are especially vulnerable to unplanned interruptions.

The best policy is to save your work frequently, especially when you are making substantive changes.

Caution – Caution –

Although it's possible to run multiple, simultaneous vi sessions on one file, it is not a good idea. Great confusion could result when you try to determine which changes have been written to the file and which changes have been overwritten from a simultaneous session.

Saving Changes and Quitting vi

vi is rich in substantively synonymous commands that control the save of the buffer contents to a file and the exit from vi. These commands give you the option of saving, saving-and-quitting, or quitting-without-saving.


Save the contents of the buffer (write the buffer to the file on disk) by typing:


Press Return.

Saving and Quitting

Save and quit by typing:


Press Return. Alternatively, type ZZ.

Note that the command ZZ is neither preceded by a colon nor followed by Return.

Quitting Without Saving

When you've made no changes to a file and want to quit, type:


Press Return. If you have made changes, vi does not let you quit with :q. Instead, it displays the following message.

No write since last change (:quit! overrides)

If you do not want to save your changes, type:


Press Return.