1

Imagine a text file with some words on the first line, one-thousand blank lines, and some text on the last line.

this is a first line of text.
<1000 blank lines>
Last line of text.

From the first line make a change and go to the last line by typing exactly: A This change will be invisible when undone from offscreen.<ESC>G.

The text is now:

this is a first line of text. This change will be invisible when undone from offscreen.
<1000 blank lines>
Last line of text.

and the cursor is on the last line and you can't see the first line.

We can press u to undo the change, but because we started offscreen from where the change actually occurred, we don't see what was undone; we just see the text as it was before the change and we have to remember what the change was that was just undone. This was a simple example but what the offscreen change was can be difficult when acutally working.

So my question is, does anyone know a way to 'preview' offscreen undos before they come into effect so that you can actually see specifically what is being undone? Or some other similar solution.

5
  • normally, pressing u moves the cursor (and hence the view) back to the changed line
    – Mass
    Sep 10, 2021 at 22:21
  • That's right but you don't see what was changed. The undo has already appened when view is at the undo location. Sep 10, 2021 at 22:24
  • Aside from toggling <C-r> and u, there’s the undotree and some plugins (at least one of which includes a small diff preview)
    – D. Ben Knoble
    Sep 10, 2021 at 22:28
  • built-in, there's always '., g; etc.
    – Mass
    Sep 10, 2021 at 23:25
  • 2
    Yeah, as noted above I just do an extra u and <c-r>. For those times when multiple steps are impacted I fire up undotree which opens up two windows: the undo history and a diff that shows what changed between the currently selected history entry and the previous entry.
    – B Layer
    Sep 11, 2021 at 2:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.