Minimal (not-)working example:
fun! Test() let save=changenr() call append(0, "THIS MUST BE UNDONE") exe "undo ".save endfun command! -nargs=0 T :call Test()
Now open a file, insert some garbage (because "undo 0" won't work), then call the command
:T three times in a row.
On my machine at least, the first two times it works as expected (i.e. does nothing). But the last time the text
THIS MUST BE UNDONE is added to the buffer. On closer inspection, the value of
save used on the third execution is 2, while the two previous ones were both 1.
What happened? (Probably something mysterious related to
edit: while I'm at it, the fact that
undo 0 does not work looks like a bug in itself. If I open a file and then do two modifications A and B, then
undo 1 puts me after A,
undo 2 puts me after A+B, but vim refuses to
undo 0 to put me before A...