What Is a .SWP File?
Vim left a .swp file and now warns you when you open the document. It is a crash-recovery file. Here is how to recover or clear it.
What a .swp file is
A .swp file is Vim's swap file — a running record of your unsaved changes, kept so it can recover your work if Vim or the machine crashes. It is normally hidden (name starts with a dot) and sits next to the file you edited.
Why Vim warns you
If a .swp already exists when you open a file, either the file is open in another Vim session or a previous session crashed. Vim shows a recovery prompt.
How to recover your work
Open the file and run :recover, or start Vim with vim -r yourfile. Compare the recovered text to the file on disk, save what you want, then delete the swap file.
Is it safe to delete?
Yes, once you have recovered (or don't need) the unsaved changes. Delete the .swp and Vim stops warning. If the file is currently open elsewhere, close that session first.
How to handle a .swp file by OS
Linux / macOS: .swp is Vim's swap file, holding unsaved edits while a file is open. If Vim warns of an existing swap on open, choose (R)ecover to restore unsaved changes, then delete the swap. You can also run vim -r file to recover.
Windows: same behaviour in Vim/Neovim; the hidden swap sits next to the edited file.
Common problems
A leftover .swp after a crash makes Vim complain the file is "already open". Recover with vim -r, save, then delete the .swp to clear the warning.
Stop the swap-file warnings for good
If the recovery prompt keeps appearing, the usual cause is a stale swap left by a crash. Clear it once: recover with vim -r file, save, then delete the hidden .file.swp sitting beside it. On Linux/macOS run ls -la to see the dot-file; on Windows it is simply named .file.swp.
Move swap files out of your working folder
To keep .swp clutter out of project directories, point Vim at one central folder. Add to your ~/.vimrc:
set directory=~/.vim/swap//
set backupdir=~/.vim/backup//Create those folders first (mkdir -p ~/.vim/swap ~/.vim/backup). The trailing // makes Vim store full-path-encoded names so two files with the same name never collide. To disable swap files entirely (not recommended — you lose crash recovery) use set noswapfile.
FAQ
How do I recover from a .swp file?
Open the file and run :recover, or launch vim -r yourfile, then save the text you want to keep.
Is it safe to delete a .swp file?
Yes, after you have recovered any unsaved changes or decided you don't need them.
Why does Vim keep making .swp files?
It writes them automatically to protect unsaved edits. You can disable them with :set noswapfile, but you lose crash recovery.
Vim says a swap file already exists — what do I do?
Choose Recover to restore unsaved changes, save the file, then delete the .swp to stop the warning.
Vim says "Found a swap file by the name" — what does that mean?
It means a .swp swap file for this file already exists, usually because the file is open in another Vim session or Vim crashed last time. Press R to recover unsaved edits, or D to delete the swap file if you don't need them.
How do I stop Vim from creating .swp files?
Add set noswapfile to your ~/.vimrc to turn them off, or set directory=~/.vim/swap// to collect all swap files in one folder instead of next to your files.
How do I delete all .swp files at once?
From the project root run: find . -name '*.swp' -delete. Only do this once you are sure none of them hold unsaved changes you still need to recover.
Other file types explained
- Are .GID Files Safe to Delete? (Windows Help Index)
- 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)
- How to Recover Unsaved Changes from a Vim .swp File
- What Is a .SWN File?
- What Is a .SWO File?
- What Is a .un~ File? (Vim Undo File)