
732
|
Chapter 9: The vi, ex, and vim Editors
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Saving and Exiting
Writing a file means overwriting the file with the current text.
Accessing Multiple Files
Window Commands
The following table lists common commands for controlling windows in vim. See
also the split, vsplit, and resize commands in the section “Alphabetical Summary
of ex Commands,” later in this chapter. For brevity, control characters are marked
in the following list by ^.
Command Action
ZZ Quit vi, writing the file only if changes were made.
:x Same as ZZ.
:wq Write file and quit.
:w Write file.
:w file Save copy to file.
:n,mw file Write lines n to m to new file.
:n,mw >> file Append lines n to m to existing file.
:w! Write file (overriding protection).
:w! file Overwrite file with current text.
:w %.new Write current buffer named file as file.new.
:q Quit vi (fails if changes were made).
:q! Quit vi (discarding edits).
Q Quit vi and invoke ex.
:vi Return to vi after Q command.
% Replaced with current filename in editing commands.
# Replaced with alternate filename in editing commands.
Command Action
:e file Edit another file; current file becomes alternate.
:e! Return to version of current file at time of last write.
:e + file Begin editing at end of file.
:e +num file Open file at line num.
:e # Open to previous position in alternate ...