I played around. Could you try the following (rarely tested):
autocmd BufReadPost * let b:undo_seq_load=changenr()
function! DiffSinceLoad()
let tmpa = tempname()
let tmpb = tempname()
let curchange=changenr()
exe "undo " . b:undo_seq_load
exec 'w '.tmpa
exe "undo " . curchange
exec 'w '.tmpb
update
exec 'tabnew '.tmpa
diffthis
vert split
exec 'edit '.tmpb
diffthis
endfunction
command! -nargs=0 DiffSinceLoad call DiffSinceLoad()
This is based on this answer.
Second iteration: This is now in my vimrc.
- Use only one temporary file
- If the buffer with the temporary file gets hidden, it is deleted.
- When the buffer with the temporary file is deleted,
:diffoff
is called via autocmd.
" store the changenr at file load
autocmd BufReadPost * let b:changenr_on_load=changenr()
function! DiffSinceLoad()
let tmpa = tempname()
let curchange=changenr()
exe "undo " . b:changenr_on_load
exe 'w ' . tmpa
exe 'undo ' . curchange
"diffthis
exe 'vertical diffsplit ' . tmpa
" when buffer gets hidden, delete it and reset diff settings
setlocal bufhidden=delete
autocmd BufDelete <buffer> diffoff
" return to edited file
wincmd p
endfunction
command! -nargs=0 DiffSinceLoad silent call DiffSinceLoad()
undotree()
. Than you might be able to determine the value of for:earlier
.:w
, and then run the command, it shows no change)