whatfileis.pro
Paste a filename and find out what it is, whether it is safe, and what opens it.

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.

Category
Safe to delete?
Opens with

What to press (decide first)

  1. You crashed / lost unsaved work → recover: press r at the prompt (or run vim -r filename). Vim loads the recovered buffer. Check it looks right, then :w to save and :e to reopen cleanly.
  2. File is open in another window: go to that session instead. If you're sure nothing is unsaved there, press o to open read-only or e to edit anyway.
  3. You don't need the swap → delete: press d to delete the .swp and 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