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 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
Difficulty level Easy
Root privileges No
Requirements vi/vim
Est. reading time N/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:




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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • w0m Apr 29, 2013 @ 4:59

    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()

  • Deepak Apr 29, 2013 @ 10:58

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

  • Sergey Apr 4, 2016 @ 16:06

    Deepak, good solution!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum