What Is a .un~ File?
Vim left a .un~ file in your folder. It is not a swap file — it stores your undo history so you can undo edits even after reopening. Here is how to manage it.
What a .un~ file is
A .un~ file is Vim's persistent undo file. When the undofile option is on, Vim saves the whole undo tree of a document to a hidden .un~ file next to it. Reopen the file later and you can still press u to undo changes from your previous session — the history survives closing Vim.
How it differs from a .swp swap file
A .swp (or .swo/.swn) is a crash-recovery file for unsaved edits and disappears when you close cleanly. A .un~ is deliberately kept so your undo history persists across sessions. Different job, different lifetime — which is why a .un~ can linger long after you saved and quit.
Why it appears in your working folder
By default Vim writes the undo file beside the document, so editing report.md leaves a hidden .report.md.un~. That clutters project folders and can end up in Git or a ZIP you share. It is created because your .vimrc (or a plugin) turned on set undofile.
Is it safe to delete a .un~ file?
Yes. Deleting a .un~ only discards the saved undo history for that document — the document itself is untouched, and Vim simply starts a fresh undo history next time you edit. On Linux or macOS: rm .yourfile.un~ (use ls -a to see hidden files). To remove them across a project: find . -name '*.un~' -delete.
How to stop or relocate .un~ files
Turn the feature off with set noundofile in your .vimrc, or keep it but move the files out of your folders with a dedicated directory: set undodir=~/.vim/undo// and set undofile. Create the folder first (mkdir -p ~/.vim/undo) so Vim has somewhere to write.
FAQ
What is a .un~ file in Vim?
It is Vim's persistent undo file — it stores the undo history of a document so you can keep undoing edits even after closing and reopening the file.
Is a .un~ file the same as a swap file?
No. A .swp/.swo/.swn recovers unsaved edits after a crash; a .un~ saves your undo history on purpose so it survives between sessions.
Is it safe to delete a .un~ file?
Yes. You only lose the saved undo history; your document is not affected and Vim starts a new history next time.
How do I stop Vim making .un~ files?
Add set noundofile to your .vimrc, or keep them but relocate them with set undodir=~/.vim/undo// so they leave your working folders.