Vim: "Found a Swap File by the Name"
When Vim shows <code>Found a swap file by the name ".file.swp"</code>, it means a <code>.swp</code> swap file already exists for that file — either Vim crashed with unsaved changes, or the file is open in another session. Press <code>r</code> to recover those changes, or <code>d</code> to delete the swap file if you don't need them. Here's exactly what to do.
What to press (decide first)
- You crashed / lost unsaved work → recover: press
rat the prompt (or runvim -r filename). Vim loads the recovered buffer. Check it looks right, then:wto save and:eto reopen cleanly. - File is open in another window: go to that session instead. If you're sure nothing is unsaved there, press
oto open read-only oreto edit anyway. - You don't need the swap → delete: press
dto delete the.swpand open normally.
After recovering
Once you've recovered and saved, the stale .swp is no longer needed. Delete it with d at the prompt, or from the shell: rm .notes.txt.swp (the swap file is usually hidden with a leading dot, in the same folder or in ~/.vim/swap). If Vim keeps warning on every open, the leftover swap file is still on disk — remove it.
Why the warning appears
Vim writes a .swp swap file to hold your edits as a crash safety net. If Vim exits cleanly, it deletes the swap automatically. The warning means it didn't exit cleanly (power loss, closed terminal, killed process) or the same file is genuinely open elsewhere. Recovering (r) is non-destructive — it loads into a new buffer and doesn't touch your original until you save.
FAQ
What does "Found a swap file by the name" mean in Vim?
A .swp swap file already exists for the file you're opening. Vim creates it to hold unsaved edits as a crash safeguard. The message means Vim either crashed with unsaved changes, or the file is already open in another session.
Should I press recover (r) or delete (d)?
Press r if Vim crashed and you might have unsaved work — recovery is safe and loads into a new buffer. Press d if you know nothing was lost (e.g. you just closed a terminal) and want to open the file normally.
How do I recover a Vim file from a swap file?
Press r at the prompt, or run vim -r filename. Vim rebuilds the buffer from the .swp. Review it, then :w to save and :e to reopen the clean file.
How do I get rid of the swap file warning permanently?
Delete the leftover .swp file — press d at the prompt, or from the shell run rm .filename.swp (it's usually a hidden dotfile in the same folder or in ~/.vim/swap). Once the stale swap is gone, the warning stops.
Other file types explained
- What Is a .ldb File? (Access Lock File That Will Not Delete)
- What Is a .dwl / .dwl2 File? (AutoCAD Lock File You Can Delete)
- What Is a .idlk File? (InDesign Lock File — Safe to Delete)
- Download Stuck at 100% But Not Finishing — How to Fix It
- What Is a ~$ File? (Word & Excel Owner File)
- What Is a File Ending in ~ (Tilde)? Editor Backup File
- Recover an Unsaved Notepad++ File After a Crash
- Vim: Swap File Already Exists — Recover, Edit, or Delete?