3

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?

2
  • 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". Commented Nov 17, 2021 at 16:46
  • @romainl That's right, thanks a lot. That was the reason why it didn't work. Commented Nov 17, 2021 at 18:35

1 Answer 1

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-----+
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.