Vim saves all your unsaved edits in a swap file, an extra file that gets deleted once the changes are committed by saving. The name of the swap file is usually the name of the file being edited preceded by a
. and with a
.swp suffix (you can see it with
So in case your vim process terminates before you've had the chance to save your edits you can recover your work by applying the changes contained in the swap file to your current file by using the command-line option
-r. For instance if
myFile is the file you were editing, use:
$ vi -r myFile
to recover the uncommitted changes.
If a swap file exists, vim should prompt you anyway for recovery options
$ vi myFile E325: ATTENTION Found a swap file by the name ".myFile.swp" ... Swap file ".myFile.swp" already exists! [O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
If you choose (R)ecover then the changes from the
swp file are applied but the swap file won't be deleted, so don't forget to delete the swap file afterwards if you're satisfied with the recovery.