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.
The full prompt, option by option
Vim offers six choices after the warning. Here is what each one does so you pick without guessing:
[O]pen Read-Only— open the file but block saving. Use this to look without risk when the file may be open elsewhere.[E]dit anyway— edit normally and ignore the swap. Risky: if another Vim really has the file open, you can clobber its work. Only choose it when you're certain no other session is live.[R]ecover— rebuild the buffer from the.swp. Always safe: it loads into memory and does not overwrite your file until you:w.[D]elete it— remove the stale swap and open clean. Use when nothing was lost.[Q]uit— back out without opening. Good when you want to go find the other session first.[A]bort— like quit, but also cancels anything queued (e.g. opening many files).
Find the swap file on disk
The warning prints the exact path (e.g. .notes.txt.swp). If you need to find it yourself, swap files are hidden dotfiles beside the original, or centralized in ~/.vim/swap/ or ~/.local/state/nvim/swap/ (Neovim). From a running Vim, :sw prints the current swap path. From the shell: ls -la in the folder, or find . -name '.*.sw?'.
Check the recovery actually worked
Recovery is only useful if the recovered buffer is newer than the file on disk. After pressing r, compare them before you save: :w recovered.txt to dump the buffer, then :!diff % recovered.txt. If the recovered version has your lost edits, save over the original with :w!. If it's identical or older, you lost nothing — quit and delete the swap.
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.
What is the difference between Open Read-Only and Edit anyway?
Open Read-Only lets you view the file but blocks :w, so you can't overwrite another session's work. Edit anyway removes that protection — only use it when you are certain no other Vim has the file open, otherwise you risk clobbering unsaved changes in the other session.
Where does Vim store swap files?
By default beside the original as a hidden dotfile (e.g. .notes.txt.swp), or in a central directory like ~/.vim/swap/ or ~/.local/state/nvim/swap/ for Neovim. Run :sw inside Vim to print the exact path of the current swap file.
How do I know if the recovered version is actually newer?
After pressing r, write the recovered buffer to a temp file with :w recovered.txt and diff it against the original: :!diff % recovered.txt. If the recovered copy contains edits missing from the file on disk, save over it; if they match, you lost nothing and can safely delete the swap.
Other file types explained
- What Is a .asv File? (Recover Your MATLAB Autosave)
- 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)
- Can I Delete .PNF Files in C:\Windows\INF? (Safe Cleanup)
- Recover a Word Document From a .wbk Backup File
- What Is an .XLK File? (Excel backup)
- Are .bak Files Safe to Delete? (Backup Files)