2

I have started using vimdiff as my git difftool, and I have accidentally used the command dp (diff put) to put some code to the other file. However, pressing u does not undo that, and vim says at the bottom "Already at oldest change"

Undoing do (diff obtain) command works perfectly, but strangely not with dp !!

Any ideas?

torek
  • 448,244
  • 59
  • 642
  • 775
H.B.
  • 148
  • 8
  • 1
    Which buffer is the current one when you do `u`? With two buffers "a" and "b", and "a" is the current one, doing `dp` changes "b", not "a", so the change must be undone from "b". With the same setup, `do` changes "a" so `u` works in "a" but not in "b". – romainl Nov 17 '21 at 16:46
  • @romainl That's right, thanks a lot. That was the reason why it didn't work. – H.B. Nov 17 '21 at 18:35

1 Answers1

4

Here is an attempt to explain the issue in a more graphical way.

$ echo 1 > a && echo 2 > b
$ vim -d a b

a is the current buffer:

+--------+--------+
| 1      | 2      |
|        |        |
|        |        |
|        |        |
+-[a]----+--b-----+

b is the target of dp so, after dp, the current buffer is unchanged and u is useless. It is the target that is changed and you can't undo a change in one buffer from another one:

+--------+--------+
| 1      | 1      |
|     == dp =>    |
|        |        |
|        |        |
+-[a]----+--b*----+

b must become current for u to work:

+--------+--------+
| 1      | 1      |
|        |        |
|        |        |
|        |        |
+--a-----+-[b]*---+ do <C-w>w to change window

after u:

+--------+--------+
| 1      | 2      |
|        |        |
|        |        |
|        |        |
+--a-----+-[b]----+

Now, let's go back to the beginning, with a being current:

+--------+--------+
| 1      | 2      |
|        |        |
|        |        |
|        |        |
+-[a]----+--b-----+

After do, it is the current buffer that is changed:

+--------+--------+
| 2      | 1      |
|     <= do ==    |
|        |        |
|        |        |
+-[a]*---+--b-----+

and the change can be undone with u without having to change windows:

+--------+--------+
| 1      | 2      |
|        |        |
|        |        |
|        |        |
+-[a]----+--b-----+
romainl
  • 186,200
  • 21
  • 280
  • 313