[Chapter 8] 8.4 Saving and Exiting
Author: Daniel Gilly & the Staff of O'Reilly & Associates
Date: 1998-08-06T21:59:55Z

#

| Chapter 8 The Vi Editor |

## 8.4 Saving and Exiting

Writing a file means saving the edits and updating the file's modification time.

ZZ | Quit vi, writing the file only if changes were made.
:x | Same as `ZZ`.
:wq | Write and quit file.
:w | Write file.
:w `file` | Save copy to `file`.
:`n1`,`n2`w `file` | Write lines `n1` to `n2` to new `file`.
:`n1`,`n2`w >> `file` | Append lines `n1` to `n2` to existing `file`.
:w! | Write file (overriding protection).
:w! `file` | Overwrite `file` with current buffer.
:w %.`new` | Write current buffer named `file` as `file.new`.
:q | Quit file.
:q! | Quit file (discarding edits).
Q | Quit vi and invoke ex.
:vi | Return to vi after `Q` command.
:e `file2` | Edit `file2` without leaving vi.
:n | Edit next file.
:e! | Return to version of current file at time of last write.
:e# | Edit alternate file.
% | Current filename.
# | Alternate filename.

8.3 Edit Commands |  | 8.5 Accessing Multiple Files