Guide
Diagnosing Vim Undofile Issues When Undo History Does Not Persist
Step‑by‑step diagnostic guide for when Vim’s undofile fails to save or restore undo history across sessions.
Published by Tasadduq Burney
30 Oct 2025, 18:00 UTC
3 min60.9K views0

Recognizable condition
You edit a file, make changes, save and quit Vim. When you reopen the same file, :undolist shows no entries and the undo (u) and redo (Ctrl+R) commands behave as if the editing session never existed. The undofile option may appear to be set, yet no undo history is retained.
Short cause/diagnostic table
| Symptom | Likely cause |
|---|---|
| :undolist empty after restart | undofile not enabled or undodirectory missing/unwritable |
| E850: Cannot create undo file | Insufficient permissions or missing directory for undofile |
| Undofile exists but undo/redo do nothing | Corrupted undo file or swap‑file interference |
| Swap file warnings at startup | Existing swap file prevents undofile handling |
| Undo works for some files but not others | Modeline overriding user undofile setting |
Ordered checks
Verify Vim’s current settings:
:set undofile? :set undodirectory?
Run these commands in Vim’s command‑line mode. Note the values; they should showundofileand a directory path.Check the undo directory from the shell:
ls -ld $HOME/.vim/undo # replace with the path from :set undodirectory?
Ensure the directory exists, is owned by you, and has write permission (e.g.,drwx------).Look for error messages when writing the undo file:
:verbose set undofile?
If Vim reportsE850: Cannot create undo file, note the path it tried to use.Detect swap‑file interference:
:sw
If a swap file is listed for the current buffer, Vim may skip undofile processing.Inspect the undo file after editing:
ls -l $HOME/.vim/undo/* # adjust path stat $HOME/.vim/undo/
The file should appear after the first save and its size should change after further edits.Test persistence:
- Open a test file:
vim test.txt - Make a change, save (
:w) and quit (:q). - Reopen the file and run
:undolist. - Undo (
u) and redo (Ctrl+R) should revert/reapply the change.
- Open a test file:
Fixes tied to findings
Undofile not enabled or directory missing
- Add to your
~/.vimrc(orinit.vimfor Neovim):
set undofile set undodirectory=$HOME/.vim/undo//
mkdir -p $HOME/.vim/undo chmod 700 $HOME/.vim/undo
Permission error (E850)
- Confirm the directory is writable by your user:
touch $HOME/.vim/undo/testwrite && rm $HOME/.vim/undo/testwrite
$HOME/.vim/undo).undodirectory accordingly.Corrupted undo file
- Remove the suspect undo file:
rm $HOME/.vim/undo/
Swap‑file interference
- List and delete stale swap files:
:ls :bd! # delete buffer associated with swap
set directory=$HOME/.vim/swap//
$HOME/.vim/swap with chmod 700.Modeline overriding user setting
- Search for modelines in the file:
:set modeline? :verbose set undofile?
modeline is on and a line like vim: set noundofile exists, either remove the modeline or add set modelines=0 to your vimrc to disable them.Escalation criteria
- After applying the relevant fix, if
:undolistremains empty, start Vim with a minimal configuration to rule out plugin interference:
vim -u NONE -N test.txt
ftplugin scripts that may undo undofile.:version) and OS details.0 replies
A thoughtful contribution can make all the difference. Be the first to share one.