Tuesday, 30 April 2013

Vi / Vim: Wipe and Undo All Changes Since Opening a File

I am a new vi / vim text editor user and I know how to quit without saving(:q!) changes. 
What if I want to wipe out all of the edits I have made in a session and get back to the original file? 
How do I wipe all changes since opening a file?


To undo and wipe all changes since opening file in vim or vi text editor.
1) If you are currently in insert or append mode, press Esc key.
2) Type : (colon). You will see the cursor at the lower left corner of the screen.
3) Type the following command:
e!
OR
edit!
The above command returns you to the last saved version of the file i.e. edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again. Type the following command for more information.
:help edit!