©2018 by Zach Pfeffer


Practice Recovering a File in Vim

April 1, 2018


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.







Please reload

Our Recent Posts

Army 20.1 SBIR TABA Funding Clarification: is $5k "On Top" of the $167,500 Available?

February 18, 2020

Contents of DoD SBIR/STTR 20.1 Cost Volume Info Pop-Ups: Fringe Benefits, Fully Loaded Labor Rate, etc. and Labor Categories

February 9, 2020

Finding Resources for Learning about Fringe, Overhead and General Management and Administration (G&A) Cost Allocation for Army SBIR Proposals

February 8, 2020

Please reload


Please reload