VI error "Found a swap file by the name"

While opening files with vi editor we come across the following error at times.

The error comes when the the file was not closed cleanly the last time it was opened, and the might done to the while during the last open might not have been saved.

For example when we close the terminal with out Quitting the file, use Cntl+z to close the file or the system shuts down abruptly when the file is open in the editor, in all the these cases vi automatically creates a .swp file of the current open file with the latest contents in it.
The next time we try to open the same file, vi editor realizes that there as swap file present for it and that might be latest file which is required and thus throws this prompt to let the user decide the further course of action.

There are 4 options to choose from

O: Open in read only mode. We can use this to confirm if the file is the latest one or not.
E: If we are not bothered about the lost changes we can directly open it and start editing it.
R: If we want to recover some of the changes that we have failed to save we can choose this option, which will try to recover the last auto saved file.
Q: Quitting with you opening the file
A: Abort the opening of the file and come back to terminal .

After choosing one of the above options and making sure that we have successfully recovered the file, we can prevent vi from throwing the message next time the file is opened we need to remove the swp file using the "rm" command. The swap file name will be ".filename.swp"

Follow by Email