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

.swp vs .swo: What's the Difference?

Both are Vim swap files holding your unsaved changes. The difference is order: .swp is the primary one, and .swo is the fallback Vim creates when a .swp for that file already exists.

Category
Safe to delete?
Opens with

Short answer

Vim writes a swap file to protect your unsaved edits. The normal name is the file plus .swp. If a .swp already exists — because another Vim session has the file open, or a previous session crashed and left one behind — Vim can't reuse that name, so it falls back to .swo, then .swn, and so on. So .swp is the first/primary swap file and .swo is the second one for the same file.

Why you're seeing a .swo

  • A stale .swp is still there from a crash or a kill — Vim won't overwrite it, so the new session grabs .swo.
  • You're editing the same file twice at once; the second Vim takes the next free extension.

Find every swap file for one document

The swap files are usually hidden (they start with a dot) and sit next to the file, or in Vim's swap directory. List them newest-first so you know which holds your latest work:

# in the file's folder, show all swap files newest-first
ls -lat .*.sw? 2>/dev/null

# or search the whole project
find . -name '.*.sw?' -printf '%TY-%Tm-%Td %TH:%TM  %p\n' | sort -r

The .sw? glob catches .swp, .swo, .swn in one shot. The most recently modified one almost always has the newest unsaved changes.

Recover your edits step by step

  1. Open the file in recovery mode: vim -r yourfile.txt. Vim lists every swap file it can recover from, with dates and the process that owned it. Pick the newest.
  2. If Vim shows the "E325: ATTENTION — swap file already exists" dialog when you open the file normally, your options are: press r to recover (load the swap contents), e to edit anyway (ignore the swap), or d to delete the swap and start clean. Choose r if you might have unsaved work.
  3. Compare swap vs disk before trusting it. After recovering, the buffer may differ from what's on disk. Run :w recovered.txt to dump the recovered buffer, then !diff % recovered.txt to see exactly what the swap adds.
  4. Save the good version over the real file with :w, then quit.

Which one do I recover from?

Recover from whichever swap file holds the newest unsaved changes — usually the most recently modified one (check timestamps with the ls -lat command above). If two sessions crashed, recover each in turn (vim -r lets you pick), save to differently-named files, and diff them to keep the best of both.

Clean up safely

Once you've saved the real file, the leftover swap files are disposable — deleting them never touches your document, and it stops the E325 warning from reappearing:

# delete all leftover swap files for a document, once you've saved
rm .*.sw?

The only risk is deleting a swap that still holds edits you never saved — so recover first, save, then delete.

Stop the warning from coming back

If the clutter annoys you, send all swap files to one folder instead of next to your files: add set directory=~/.vim/swap// to your ~/.vimrc (create the folder first). The trailing // makes Vim encode the full path into the swap name so two files never collide. To turn swap files off entirely (not recommended — you lose crash recovery), use set noswapfile.

Are they safe to delete?

Yes — once you've saved your work, both .swp and .swo are disposable. They only exist to recover unsaved edits; deleting them never touches the real file. The only risk is deleting one that still holds changes you never saved.

FAQ

What's the difference between .swp and .swo in Vim?

They're both swap files for the same edited file. .swp is the primary name Vim uses; .swo is the fallback it creates when a .swp already exists (e.g. after a crash or a second open session).

Why did Vim create a .swo instead of a .swp?

Because a .swp for that file was already present. Vim never overwrites an existing swap file, so it steps to the next extension: .swo, then .swn, and so on.

Which swap file should I recover from?

The one with the newest unsaved changes — usually the most recently modified. Run 'vim -r yourfile' and pick the swap file Vim lists with the latest timestamp.

Is it safe to delete .swp and .swo files?

Yes, after you've saved your work. They only hold recovery data; deleting them doesn't affect the real file. Don't delete one that still contains edits you never saved.

How do I see all the swap files for one file?

Run 'ls -lat .*.sw?' in the file's folder (or 'find . -name ".*.sw?"' for a whole project). The .sw? glob matches .swp, .swo and .swn at once; the newest-modified one usually holds your latest unsaved edits.

What does E325 'swap file already exists' mean and what do I press?

Vim found a leftover swap file when opening your document. Press r to recover the unsaved changes, e to edit anyway ignoring the swap, or d to delete the swap and start clean. Use r if you might have unsaved work.

Other file types explained