Skip to content

Hooks for tweaking diff highlights #52

@yorickpeterse

Description

@yorickpeterse

I realise this is a bit of an odd request, but here goes anyway:

Highlighting of diffs in (Neo)Vim is a counter-intuitive. When you have version A and B of a file and diff them, A will show the diff relative to B, while B shows the diff relative to A. In practise this means that e.g. a line removed by B shows up as an addition in A, while not showing up in B. Here's an example of that:

Screenshot from 2021-08-02 18-02-24

In addition, changes in B tend to highlighted using the DiffText highlight group. This can result in diffs largely looking similar highlight wise, making it difficult to see what actually changed.

For vim-fugitive I have a hack to fix this (see here). This basically uses winhl to overwrite highlight groups in the appropriate fugitive buffer. The result is something that looks like this:

Screenshot from 2021-08-02 18-05-06

Note how in the old version (left) deletions are shown in red, while additions in the new file (right) are in green. This is what you'd expect when looking at a diff, instead of the default Vim mess.

For diffview.nvim this doesn't work. Buffer names don't have predictable names I can use to inject my winhl rules. There are no hooks of any kind that I can tap into either. Which brings me to my request:

Would it be possible to somehow expose a hook that runs for old/new versions in a diff, or perhaps use specific buffer names (e.g. before: diffview/XXX.rb) for old/new versions? That would make it possible to fix the diff highlights.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions