weynhamz
weynhamz

Reputation: 2008

Is there a way to view two diffs in one vim tab?

I know that the diffs in vim are local to page, this means we can only have one diff in one tab page, right? But what if I want to have two diffs in one tab page. Eg, one diff is between the top two windows, and the other diff is between the bottom two windows. This is a commn sinerio in dealing with git merge confilict. We can have the remote commit changes diff in top two windows and the local file and local confilict file diff in bottom two windows, then, we konw exactly what have been changed in the remote caused the confilct and manuuly fix them up.

How can I do that? Is there any plugin?

Upvotes: 0

Views: 271

Answers (2)

user2987828
user2987828

Reputation: 1137

If you want to compare A.txt to B.txt and A.java to B.java, you can do:

echo two way diffs separator > separator
cat A.txt separator A.java > A
cat B.txt separator B.java > B
vimdiff A B

Then enter the commands

G:sp|set noscrollbind|normal gg<enter> to split left pane and debind scroll of new pane,

<c-W>l to go go right pane,

G:sp|set noscrollbind|normal gg<enter> to do the same thing to right pane.

Of course, it is not ideal: cursor of top windows are not linked, and each buffer also contain the other buffer if you scroll down or up too much.

Upvotes: 0

Ingo Karkat
Ingo Karkat

Reputation: 172540

Participation of a buffer in a diff is determined by the 'diff' buffer setting for all buffers visible within a tab page (for up to four buffers). Implementing what you desire would need a notion of "diff groups", e.g. :setlocal diff=group1, but something like this does not exist today.

The only way to achieve this today without a patch to Vim (that I can think of) is running two separate Vim instances in a split-window screen or tmux session.

Upvotes: 1

Related Questions