The :w command saves the current buffer (analogous
to `save' in a graphical editor). If you specify <filename>, the contents
of the buffer is written to a different file. If you specify a filename,
you normally won't be able to specify an already-existing file. If
you must overwrite that file anyway, then add a ! after the w.
:w! foo.bar
saves the buffer to foo.bar whether or not foo.bar
already exists.
How do I edit a different file?
:e
<filename> :e! The :e command either reloads the current file,
or the file specified if <filename> is given. If your buffer has been
modified and not yet saved, you won't be able to reload the buffer
unless you add a ! after the e.
:e! foo.bar
start editing foo.bar, discarding changes currently
made to the buffer.
How do I embed another file?
:r <filename>
Reads the contents of <filename> and embeds it into
the current buffer.
:r !<command>
Executes <command> and embeds into the buffer the
output generated by the command.
:r !fortune -s
puts a short fortune into your buffer--my favourite
way of making email signatures.
Gettin' outta here.
:wq ZZ
Both of these do pretty much the same thing, save changes
made to the buffer and exit vi.
:q!
Quits vi, discarding all changes made to the editing buffer.