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

How to Safely Delete a Vim Swap File

If Vim keeps warning about a swap file you don't need, delete it — but check it first. Quit Vim, run a one-line recovery to peek at what's inside, and if there's nothing worth keeping, remove the hidden <code>.swp</code> file. Here's the safe way.

Category
Safe to delete?
Opens with

Delete it (the safe way)

  1. Peek first so you don't throw away unsaved work: vim -r yourfile.txt opens recovery mode. If it's identical to the saved file, there's nothing to lose.
  2. Quit Vim completely (no session should hold the file).
  3. Delete the hidden swap: rm .yourfile.txt.swp. Swap files are dotfiles — list them with ls -a.

Delete it from inside Vim

At the E325 prompt you can press (D) to delete the swap immediately. Or, after recovering, run :call delete(v:swapname) to remove the current swap without leaving Vim.

If the swap lives in a central folder

Some setups store swaps in one directory instead of beside the file. Find it with :set directory? — common locations are ~/.vim/swap/ or ~/.local/state/nvim/swap/ for Neovim. Clear old ones with rm ~/.vim/swap/*.swp once you're sure no Vim is running.

Stop it coming back

If swaps annoy you on scratch files, disable them per-session with :set noswapfile, or globally in your .vimrc with set noswapfile. Only do this if you accept losing crash recovery for those files.

FAQ

How do I delete a Vim swap file?

Quit Vim, then delete the hidden file with rm .yourfile.swp (list hidden files with ls -a). From inside Vim you can press (D) at the swap prompt, or run :call delete(v:swapname).

Is it safe to delete a .swp file?

Yes, once you're sure it holds no unsaved work. Check first with vim -r yourfile — if recovery shows nothing new versus your saved file, the swap is stale and safe to remove.

Where does Vim keep swap files?

By default beside the original as a hidden dotfile (.name.swp). If the 'directory' option is set they live in one folder such as ~/.vim/swap/ or ~/.local/state/nvim/swap/. Check with :set directory?.

Other file types explained