vim undo

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

vim undo

Chris Jones-44
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.

Thanks,

CJ

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200304180054.GA4040%40turki.local.
Reply | Threaded
Open this post in threaded view
|

Re: vim undo

Tim Chase
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.

-tim


--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200304121950.7fbf49a1%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: vim undo

Bram Moolenaar

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 -- [hidden email] -- 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/202003042222.024MM7du020885%40masaka.moolenaar.net.
Reply | Threaded
Open this post in threaded view
|

Re: vim undo

Chris Jones-44
In reply to this post by Chris Jones-44
On Wed, Mar 04, 2020 at 01:00:54PM EST, Chris Jones wrote:

Thanks to both for timely response.

Interesting answers indeed.

Looking at my problem from a different angle I eventually noticed
something that allowed me to single out the outcome of the incorrect
changes and let me reverse them without affecting the ensuing editing.

Thank you.

CJ

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200305160331.GB4040%40turki.local.