VIM:: Undo changes on or around the specified text
Asked Answered
O

2

5

In VIM is it possible to undo changes on or around a specific block of text? Lets say I make change A right above "if yes", then do changes B, C, D and E in other places on the file. Is it possible to tell vim "undo changes that were done with in +/- 10 lines from if yes?

I've come across another question that suggest this isn't possible, or at least in vanilla vim. Does any know of any plugins that would allow for this behavior?

Ossifrage answered 7/4, 2011 at 18:3 Comment(0)
L
4

With this plugin: http://www.vim.org/scripts/script.php?script_id=3304 you can easily move around the undo tree.

  1. So just go back to the original section (around if yes), mark it with ma,
  2. Go back to it's previous state on the tree (even if it undoes other changes).
  3. Copy (yank) the region you want to keep to a register (e.g. select visual lines - V5j"by).
  4. Get back to the actual state (last item on the Gundo tree).
  5. Jump back to the section you want to change ('a)
  6. Deleted the section you want to revert, and replace it with the contents of b register.
Leukemia answered 7/4, 2011 at 19:38 Comment(3)
I've actually wanted to use Guno for some time, but the server I'm running off of is using VIM 7.1 and that requires 7.3 :LOssifrage
Actually I had compiled Vim to my home dir on a big server which won't get upgraded any time soon from Vim 6.0 ;-)Leukemia
I tried compiling from src without root access and configure complains (error) about missing "ncurses" :L I can't install it without root :OOssifrage
G
12

@Zsolt's answer is probably very interesting, I'd have to get acquainted with that.

What I usually do is, doing something like

100g- (go back to history snapshot that contained the thing you want to restore)

yank your 'rescue' text using some method, e.g.

:12,17yank

999g+ (return to the tip of history)

use regular edit actions to restore the yanked lines into place.

Gapes answered 7/4, 2011 at 23:16 Comment(1)
(Actually it's "Zsolt" :-) but never mind.) And thank you for teaching me about g- and g+.Leukemia
L
4

With this plugin: http://www.vim.org/scripts/script.php?script_id=3304 you can easily move around the undo tree.

  1. So just go back to the original section (around if yes), mark it with ma,
  2. Go back to it's previous state on the tree (even if it undoes other changes).
  3. Copy (yank) the region you want to keep to a register (e.g. select visual lines - V5j"by).
  4. Get back to the actual state (last item on the Gundo tree).
  5. Jump back to the section you want to change ('a)
  6. Deleted the section you want to revert, and replace it with the contents of b register.
Leukemia answered 7/4, 2011 at 19:38 Comment(3)
I've actually wanted to use Guno for some time, but the server I'm running off of is using VIM 7.1 and that requires 7.3 :LOssifrage
Actually I had compiled Vim to my home dir on a big server which won't get upgraded any time soon from Vim 6.0 ;-)Leukemia
I tried compiling from src without root access and configure complains (error) about missing "ncurses" :L I can't install it without root :OOssifrage

© 2022 - 2024 — McMap. All rights reserved.