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.
Delete it (the safe way)
- Peek first so you don't throw away unsaved work:
vim -r yourfile.txtopens recovery mode. If it's identical to the saved file, there's nothing to lose. - Quit Vim completely (no session should hold the file).
- Delete the hidden swap:
rm .yourfile.txt.swp. Swap files are dotfiles — list them withls -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
- Is It Safe to Delete .tmp Files?
- Chrome Download Stuck as .crdownload (Not Finishing) — Fix
- Safari .download File Stuck (Not Finishing) on Mac — Fix
- Opera .opdownload Stuck / Not Completing — Fix
- Firefox .part File Won't Finish Downloading — Fix
- .partial File Won't Finish Downloading (Edge/IE) — Fix
- What Is a .001 File? (split archive part)
- What Is an .AAE File? (iPhone photo edits)