How to suspend VIM history

vim

When we edit a file, we usually do many UNDO in a row, say, 20 times. In VIM, that is usually performed by pressing u 20 times, and that makes VIM go "up" in the history stack 20 positions. If you then make a certain change, all those last 20 history commands are lost, and replaced by change. I would like to make the change without loosing those 20 positions. So I guess I would like to tell VIM to stop recording history before I do change, and resume history afterwards (don't want change in history).

EDIT
Trying to be more clear: I have a function FF that updates the last lines of a file when the buffer is written. So, if I perform 20 undos + write, the last write opens a new undo branch. I tried adding undojoin inside FF (trying to follow a suggestion by jlmg below), but a sequence write-undo-write gives an error: undojoint not allowed after undo. I could instead do some sed .... after leaving vim instead, but since I use this through SSH I prefer a vim-only solution (execute a command after unloading the buffer does not write to the file).

EDIT 2 Try to do this in VIM: open a blank file, and do:

i1<ESC>:wa2<ESC>:wa3<ESC>:wa4<ESC>uu:w

If now you do a <CTRL>R, VIM will write the '3' back, a further <CTRL>R you get the 4. This happens EVEN if you do a:w after each <CTRL>R. However, if each time you do a :w you execute a fuction via BufWritePre, the <CTRL>R will not write the 3 back. And this is what I want to do, that's why I wrote to 'suspend hisotry', but maybe what I am asking is not possible, besides working with the full undotree().

Best Answer

You don't need to suspend Vim history. The actual data forms a tree, and you can retrieve it with the undotree() function. There are, of course, a number of plugins that turn that into something more user-friendly, f.i. gundo, mundo, and undotree. If you also enable undo persistence (cf. :h undo-persistence) you can easily navigate through the entire change history of a file.

Related Question