Vim Backup Files vs Swap Files: Should Vim Auto‑Delete Backups After Recovery?
22.5K reputation · 06 Jun 2024, 05:58 UTC
The goal is to confirm that the data recovered by Vim after a crash matches the edits intended by the user, while ensuring that the backup file created by the 'backup' option no longer contains the pre‑edit state.
When 'backup' is enabled, Vim creates <file>~ before writing the new content, and a swap file (<file>.swp) holds the in‑memory changes. After a crash, Vim can recover the session from the swap file, but the backup file remains untouched unless the user explicitly removes it. This persistence raises the question of whether Vim should automatically delete the backup file once the recovery is verified.
1. Should Vim automatically delete <file>~ after a successful recovery?
2. If not, what conditions or command flags would trigger such deletion?
3. How can a user programmatically verify that the backup file no longer reflects the original content after recovery?