vimdiff: Different colors for left and right pane

633 views Asked by At

I've started using vimdiff and I'm trying to set up colors for it. The DiffAdd and DiffDelete groups work fine, however I would like DiffChange and DiffText to be different colors for the old and new version of the file respectively. (Specifically, red for the old file, and green for the new. This is how Visual Studio Code works, for example.

The problem is that highlight colors are shared between buffers. Is there a way around this? I was hoping there would be a way to write a function that would remap all instances of DiffChange to MyDiffChange in a pane, but I haven't found a way to do that.

Even a fairly hacky solution would do since it only has to work for this specific use case.

1

There are 1 answers

0
Ingo Karkat On

The highlight definitions indeed are globally scoped, and much of the diff handling is fixed and built-in. You are correct that Vim does not support this.

As a hack, you can override the highlighting via matchadd() with a higher priority. These definitions are window-scoped, so you can define different ones based on what the file represents (I would use a buffer-local variable b:version, with values of old or new). You need to detect the lines that Vim considers changed, either by diffing the files again yourself, or via diff_hlID(). Have a look at diffchar.vim plugin for ideas; the plugin implements a similar overlay.