Wednesday, March 4, 2020

Re: vim undo

Tim Chase wrote:

> On 2020-03-04 13:00, Chris Jones wrote:
> > Scenario:
> >
> > - I open a file
> > - I make one big global change (C0)... say via substitute+regex
> > - I proceed to make more changes (C1, C2, ... Cn).
> >
> > While *still editing the file* I realize that the initial change
> > (C0) was in error.
> >
> > Can I undo the initial change (C0) and keep all the ensuing changes?
> >
> > Or...
> >
> > Go back to the initial state of the buffer, and make vim reapply
> > all the C1-Cn changes?
> >
> > Standard vim only please, no plugins.
>
> I don't think there's a native way to play back all the changes as a
> rebase. If I had a dire need to do as much, I'd do a little
> do/undo/diff/patch tango, something like
>
> :w current.txt
>
> then undo to C1
>
> :w c1.txt
>
> then undo once more take you back to the pre-C0 change and save that:
>
> :w pre-c0.txt
>
> Then, in the shell
>
> $ diff -u c1.txt current.txt > rest_of_the_changes.txt
>
> and run that patch against the pre-c0.txt
>
> You might be able to use git to checkin various points and then
> use its rebasing to help you out.
>
> But in pure vim? Not much.

You can do it without leaving Vim:

:w new_version
(undo until the big change is undone)
:vimdiff new_version
(diffget to get the changes you want)

If there are overlaps it's more work. If there are many changes then
the diff + patch tools might work better, but likely "patch" will find
conflicts and it's not good at dealing with those.

--
hundred-and-one symptoms of being an internet addict:
175. You send yourself e-mail before you go to bed to remind you
what to do when you wake up.

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/202003042222.024MM7du020885%40masaka.moolenaar.net.

No comments:

Post a Comment