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

by on April 28, 2013 · 2 comments· LAST UPDATED April 28, 2013

in , ,

I am a new vi / vim text editor user and I know how to quit without saving 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?

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsvi/vim
Estimated completion timeN/A
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!

Check out related media

This tutorial is also available in a quick video format:


Video 01: VI / VIM: Wipe All Changes To The Buffer / File

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 2 comments… read them below or add one }

1 w0m April 29, 2013 at 4:59 am

I use this daily. Though to be safe; I do a diff of current buffer and file saved on disk before reverting.
0 set diffopt+=iwhite
1 function! DiffOrig()
2 if &diff
3 wincmd p | bdel | diffoff
4 else
5 vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis
6 endif
7 endfunction
8 map do :call DiffOrig()

Reply

2 Deepak April 29, 2013 at 10:58 am

easiest way is, type escape and then “u” to undo the changes one by one.

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: