vim: revert a specific change in the undo history

15 views
Skip to first unread message

ping song

unread,
Jul 11, 2023, 8:20:21 AM7/11/23
to vim-use Mailingliste
say I've done 3 changes A, B, C.
but I realized B is a big mistake. A and C is good.
can I just delete change B, but keep A and C?

Christian Brabandt

unread,
Jul 11, 2023, 3:26:40 PM7/11/23
to vim...@googlegroups.com
I believe this is not possible. What you can do is, copy the whole
buffer at state C, move back to state A and clear the buffer and paste
the content from State C (effectively creating a new change A->D)

Best,
Christian
--
Spielen ist eine Tätigkeit, die man gar nicht ernst genug nehmen kann.
-- Jacques Yves Cousteau

A. S. Budden

unread,
Jul 11, 2023, 3:56:17 PM7/11/23
to vim...@googlegroups.com
On Tue, 11 Jul 2023, 20:26 Christian Brabandt, <cbl...@256bit.org> wrote:

On Di, 11 Jul 2023, ping song wrote:

> say I've done 3 changes A, B, C.
> but I realized B is a big mistake. A and C is good.
> can I just delete change B, but keep A and C?

I believe this is not possible. What you can do is, copy the whole
buffer at state C, move back to state A and clear the buffer and paste
the content from State C (effectively creating a new change A->D)

An alternative would be to use the history commands to get at each version and either use diff/patch tools or a 3-way merge tool like BeyondCompare to sort it out.

e.g. (untested):

* Open file at State C
* :w statec.txt
* Revert to State B
* :w stateb.txt
* Revert to State A
* :w statea.txt
* diff -u stateb.txt statec.txt > c_changes.diff
* patch -p0 statea.txt < c_changes.diff

(check all of those commands before running as they were off the top of my head!)

Eike Rathke

unread,
Jul 11, 2023, 6:30:47 PM7/11/23
to vim...@googlegroups.com
Hi ping,
Not directly; you could save file and use Mundo
https://github.com/simnalamburt/vim-mundo to jump to the diff of B,
write the preview to patchfile, switch to editfile and run patchfile
through
!patch -R % patchfile
and reload the file. A tad cumbersome though..

There's https://github.com/simnalamburt/vim-mundo/issues/20 but never
resolved.

Eike

--
OpenPGP/GnuPG encrypted mail preferred in all private communication.
GPG key 0x6A6CD5B765632D3A - 2265 D7F3 A7B0 95CC 3918 630B 6A6C D5B7 6563 2D3A
Use LibreOffice! https://www.libreoffice.org/
signature.asc
Reply all
Reply to author
Forward
0 new messages