One of the new features in Vim 7.3 is \'persistent undo\', which allows for the undotree to be saved to a file when exiting a buffer.
Unfortunately, I haven\'t quite
Put this in your .vimrc
to create an undodir
if it doesn't exist and enable persistent undo. Tested on both Windows and Linux.
" Put plugins and dictionaries in this dir (also on Windows)
let vimDir = '$HOME/.vim'
let &runtimepath.=','.vimDir
" Keep undo history across sessions by storing it in a file
if has('persistent_undo')
let myUndoDir = expand(vimDir . '/undodir')
" Create dirs
call system('mkdir ' . vimDir)
call system('mkdir ' . myUndoDir)
let &undodir = myUndoDir
set undofile
endif
I suppose $HOME doesn't work as advertised.
On my system, :echo $HOME
shows H:\, but : e $HOME/
says: ~/
invalid filename.
You could try with an absolute path to see whether it cures it
If you are looking for %TEMP%.(filename).un~ you won't find it
The filename will be something line C%%Users%%(username)%_vimrc
I have no idea why
I tried this in my _gvimrc:
" Persistent undo
try
set undodir=C:\vim\undodir
set undofile
catch
endtry
It started working as advertised when I deleted the try-catch bracket, thus:
" Persistent undo
set undodir=C:\vim\undodir
set undofile
I had to create the directory.
This now works as expected: file.txt
open in a Vim 7.4 buffer on Windows 7, :setlocal undofile
, then save a change to the buffer, and the undofile .file.txt.un~
is created alongside because :set undodir?
reports that "undodir=." by default - ie no need to specify this manually. You can also :set undofile
in a modeline.