< Zurück | Inhalt | Weiter >

2.2.1 Exiting

There are three ways of exiting vi (ZZ, :q, :q!) that you should know. The correct one to use depends on whether or not you want to save the changes to the file and on whether or not you have saved your changes.

ZZ saves and quits in one step (three keystrokes).

:w writes what you’ve been editing but doesn’t quit.

:w filename writes what you’ve been editing to a new file named filename; it will complain (and not write out anything) if the file already exists.


:7,.w! filename writes lines from line 7 up to and including the current line to the named file, clobbering any previous contents (think of the “!” as meaning “and don’t argue with me!”).

:q quits, provided you’ve saved your changes (e.g., with :w).

:q! quits without saving any changes to the file.

:n doesn’t exit vi, but moves on to the next file if you started up with more than one file to edit (e.g., vi Fir.java Pine.java). When you’ve reached the last file in the list, you need to quit—for example, with :q.