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

Steps

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.

6.

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.

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:

Overwrite hello.c with hello.c.recovered, Delete the hello.c.recovered buffer ...and delete the hello.c.recovered file

15. Check that everything is cleaned up. Run:

You should see

References