Quitting Without Saving Edits
When you are first learning vi, especially if you are an intrepid experimenter, there are two other ex commands that are handy for getting out of any mess that you might create.
What if you want to wipe out all of the edits you have made in a session and then return to the original file? The command:
:e!ENTERreturns you to the last saved version of the file, so you can start over.
Suppose, however, that you want to wipe out your edits and then just quit vi? The command:
:q!ENTERquits the file you’re editing and returns you to the Unix
prompt. With both of these commands, you lose all edits made in the
buffer since the last time you saved the file. vi normally won’t let you throw away your
edits. The exclamation point added to the :e or :q
command causes vi to override this
prohibition, performing the operation even though the buffer has been
modified.
Problems Saving Files
You try to write your file, but you get one of the following messages:
File exists File
fileexists - use w! [Existing file] File is read onlyType
:w!fileto overwrite the existing file, or type:wnewfileto save the edited version in a new file.You want to write a file, but you don’t have write permission for it. You get the message “Permission denied.”
Use
:wnewfileto write out the buffer into a new file. If you have write permission for the directory, you can usemvto replace the original version with your copy of it. If you don’t have write permission for the directory, type ...