• Zach Pfeffer

Practice Recovering a File in Vim

This post lists steps that allow you to practice file recovery in Vim.


1. Open a terminal, create a directory and start editing a file named hello.c:

2. Put this text in the file:

3. Save the file in Vim:

4. Make a change to the file but _don't_ save:

5. Close the terminal.


You should see:

7. Type 'Q' to quit

8. Open the file in recovery mode:

You should see:

9. After pressing ENTER, write the file out to check the recovery:


10.1 When you see the following type 'O'

10.2 Now you should see:

Control-w j and Control-w k will let you switch between the windows

11. To exit diff mode type:

11.1 To remove one of the windows use Control-w j or Control-w k to enter the window then type ZZ.

12. Now find and save the right buffer. Find the right buffer:

At the following, press '2':

13. Now delete the swap file.

13.1 Edit the file

13.2 At this screen type 'D' to delete:

14. Now:

  1. Overwrite hello.c with hello.c.recovered,

  2. Delete the hello.c.recovered buffer

  3. ...and delete the hello.c.recovered file

15. Check that everything is cleaned up. Run:

You should see


  • Steps adapted from the Vim user doc @ link.

  • The Vim logo is from link.

  • Used the HTML escape feature at FreeFormatter.com for the code blocks.

Our Recent Posts



©2020 by Zach Pfeffer