Swap File Compatibility After Upgrading from Vim 8 to Vim 9
0 reputation · 07 Feb 2025, 01:14 UTC
0 reputation · 07 Feb 2025, 01:14 UTC
Recover a file after a failed Vim upgrade without data loss.
Swap files created by Vim 8 become stale or incompatible in Vim 9; Vim warns but does not auto‑clean.
The documentation does not specify whether Vim should automatically delete or rename stale swap files on startup after an upgrade.
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.
If you have a stale swap file from Vim 8 and need to recover data in Vim 9, follow these steps:
(R)ecover.:w to commit the recovered changes to the disk.:set directory?.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.
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.
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.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 07 Feb 2025, 07:53 UTC
The existing answer correctly notes that Vim 9 reads Vim 8 swap files but emits an E325 warning. A quick way to verify which major version produced a given .swp file is to examine its header:
strings /path/to/file.swp | head -5
Output typically includes a line such as VIM 8.2 or VIM 9.0 near the top. If the major version differs from vim --version | head -1, the E325 is expected and recovery is safe. Point releases (e.g., 8.2 vs 8.3) can also trigger the warning even within the same major version, so the header check avoids guesswork.
Caution: Deleting the .swp without running :recover first discards any unsaved changes captured at crash time.