Learning the vi Editor

Learning the vi EditorSearch this book
Previous: 1.1 Opening and Closing Files Chapter 1
The vi Text Editor
Next: 2. Simple Editing
 

1.2 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! [RETURN]

returns 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! [RETURN]

quits 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.

1.2.1 Problems Saving Files

1.2.2 Exercises

The only way to learn vi is to practice. You now know enough to create a new file and to return to the UNIX prompt. Create a file called practice, insert some text, and then save and quit the file.

Open a file called practice in the current directory:vi practice
Insert text:i any text you like
Return to command mode:[ESC]
Quit vi, saving edits:ZZ


Previous: 1.1 Opening and Closing Files Learning the vi EditorNext: 2. Simple Editing
1.1 Opening and Closing Files Book Index2. Simple Editing

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System