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

Vim: 'Swap File Already Exists' — What to Do

When Vim warns <strong>E325: ATTENTION — Found a swap file by the name</strong> or <strong>'Swap file ".file.swp" already exists!'</strong>, it found a leftover <code>.swp</code> — either another Vim still has the file open, or a session crashed. If the prompt line says <strong>'(process ID … still running)'</strong>, press <strong>(Q)uit</strong> and edit from that other session. Otherwise press <strong>(R)ecover</strong> first to pull back unsaved edits, compare them, then delete the stale swap.

Category
Safe to delete?
Opens with

First: is a session still running?

Read the prompt carefully. Vim prints the owner process. If it shows process ID: 1234 (still running), a second Vim really has the file open — do not recover. Press Q (Quit) or A (Abort) and switch to that session. Recovering now would fork your edits into two copies.

If the process is gone (crash)

No '(still running)' means the previous edit crashed and left the swap behind. Safe order is (R)ecover → inspect → delete:

  1. Press r to recover. Vim rebuilds the buffer from the swap.
  2. Save under a new name so you don't clobber the original: :saveas yourfile.recovered.
  3. Diff against the on-disk file to see exactly what the swap adds: :diffsplit yourfile.txt.
  4. Keep the version you want, then delete the swap: quit Vim and rm .yourfile.txt.swp (it's hidden — list with ls -a).

The prompt options at a glance

  • (O)pen Read-Only — view only, no unsaved changes.
  • (E)dit anyway — ignore the swap; risky if another Vim has the file.
  • (R)ecover — rebuild from swap. Start here after a crash.
  • (D)elete it — remove the swap; only once you've recovered what you need.
  • (Q)uit / (A)bort — back out, change nothing.

Stop the warning coming back

If you recovered but the warning keeps appearing, a stale .swp is still on disk. Close all Vim instances, then remove it manually. To relocate swaps out of your working dir entirely, set :set directory=~/.vim/swap// in your ~/.vimrc (create the folder first).

FAQ

Vim says the swap file already exists — recover or delete?

Recover first if the process is NOT still running: press (R), save to a new name, diff against the original, then delete the swap. If the prompt says '(still running)', a second Vim has the file open — quit and use that session instead of recovering.

What does '(process ID still running)' mean?

Another Vim process currently has the file open. Recovering would create two divergent copies. Press Q or A to abort, switch to the open session, or close it first, then reopen the file.

How do I delete the Vim swap file?

Quit Vim, then run rm on the hidden swap, e.g. rm .yourfile.txt.swp. Swap files start with a dot and end in .swp (or .swo/.swn for extras), so list them with ls -a.

How do I stop Vim creating swap files or showing this warning?

You can move swaps out of your working directory with :set directory=~/.vim/swap// in ~/.vimrc, or disable them with :set noswapfile (you then lose crash recovery). Clearing leftover .swp files also stops a repeating warning.

Other file types explained