Recovery and Compatibility
Vim does not automatically delete or rename swap files created by a prior major version. Vim 9 is designed to be backward compatible with swap files created by Vim 8, meaning you can typically recover unsaved data across this version jump without manual intervention.
Recovery Procedure
If you have a stale swap file from Vim 8 and need to recover data in Vim 9, follow these steps:
- Open the affected file with Vim 9.
- When the Swap file exists warning appears, press
(R)ecover.
- Verify that the recovered content is correct.
- Save the file using
:w to commit the recovered changes to the disk.
- Exit Vim and manually delete the swap file to prevent the warning from reappearing. You can find the swap file path in the initial warning message or by using
:set directory?.
Technical Explanations
Automatic Cleanup: Vim avoids automatic deletion of swap files because it cannot determine if a file is "stale" due to a version upgrade or if it represents critical unsaved data from a system crash. Deleting these files automatically would risk permanent data loss.
The Role of 'backupcopy': The backupcopy setting determines how Vim handles the original file when saving a backup. It does not affect the .swp file's internal structure or the ability of the :recover command to extract data from a swap file. Recovery reads from the swap file directly into the buffer, bypassing the standard save/backup mechanism.
Verification
To verify compatibility in a safe environment, you can simulate a crash:
# In Vim 8
vi test.txt
# Make changes, then force quit without saving
:q!
Then, open the file in Vim 9. If the recovery prompt appears and :recover restores the text, the compatibility is confirmed for your specific environment.
Diagnostic Requirement
If the recovery prompt does not appear despite the existence of a .swp file, please specify if you changed your directory setting or migrated the files to a different filesystem/OS architecture during the upgrade, as this can affect file discovery.