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()
.
vi
, but to mevi
's undo command undoes once, and then when you pressu
again it undoes the undo ("redo"). That's real vi. So I and other users of this site might not know the answer to your question.vim.se
, I would have tried that. Anyway, it seems Sato knows how to help.sed
, but sed can't do your undos, so how's that going to work? If you were able to "suspend history", what kind behaviour would you expect of vim when you do an undo afterwards? The only behaviour I could visualize is to group those changes (along with the undos) in one undo block, hence my answer. But if that's not it, what is?