diffview-plus.nvim icon indicating copy to clipboard operation
diffview-plus.nvim copied to clipboard

[Discussion] Bezier ribbons between diff windows with kitty graphics protocol

Open lucobellic opened this issue 1 week ago • 0 comments

This issue only presents an experiment I wanted to share to show that the idea works with diffview-plus.nvim as it is today.

Feel free to close the issue or move it to a discussion "Show and Tell" section.

Summary

I found that diffbandit.nvim draws smooth bezier "connector ribbons", like the divider in JetBrains, which was nice
but I didn't want to switch to a new plugin only for the extra rendering.

I used Opus 5.5 to write a small local plugin (about 1,800 lines of Lua) that adds the ribbons on top of a normal diffview-plus.nvim view using kitty graphics protocol.

image image image

This local plugin is tailored for my personal configuration and can be found in https://github.com/lucobellic/nvim-config/tree/main/local/diff-ribbon
If anyone is interested in it for its own use, or maybe to be added directly in diffview-plus.nvim as an option.

Details: what it does, how it plugs in, how it is drawn, limitations

What it does

  • Draws one ribbon in each separator between two windows that sit side by side:
    • diff2_horizontal and diff2_horizontal_pinned: one ribbon.
    • diff3_horizontal: two ribbons (OURS | LOCAL, LOCAL | THEIRS).
    • diff3_mixed: one ribbon between the two top windows.
    • diff4_mixed: two ribbons between the three top windows.
    • Vertical layouts and diff1_* get nothing, because no window sits next to another one.
  • Hides the filler lines while the ribbons are shown, so each side keeps its real shape. Neovim's scrollbind still keeps the sides aligned through the diff.
  • Colors the line number column of changed lines and underlines insertion points with the ribbon color, so each band runs from the text, through the gutter, to the other side. This uses number_hl_group extmarks, which Neovim's own number column shows as is. A custom statuscolumn that sets its own highlights has to read these marks to show the band (mine does, to color the whole gutter).
  • Takes the colors from the diff highlights in each window, including the winhighlight remaps of diffview-plus.nvim (for example red deletions on the left with enhanced_diff_hl).
  • Fully added or deleted files get no ribbon, because one side is empty.
  • Can be toggled at any time. Turning it off brings the filler lines back.

How it plugs into diffview-plus.nvim

Only reading is needed: diffview-plus.nvim is never patched and its buffers are never changed.

  • Hooks: a refresh is scheduled from view_enter, view_leave, view_closed, view_post_layout and diff_buf_win_enter.
  • Current view: require('diffview-plus.nvim.lib').get_current_view(), then view.cur_layout.
  • Layout: layout.name to know the layout, layout.a, .b, .c, .d for the windows, and Window:is_nulled() to skip files that only exist on one side.

Everything else is plain Neovim: window positions, scroll events (WinScrolled, WinResized), and vim.text.diff.

How it is drawn

  • Kitty graphics protocol with Unicode placeholders. The ribbon image is shown through placeholder characters in a small floating window over the separator. The float scrolls, clips and stacks like any other Neovim float, so popups still cover it.
  • Sent through nvim_ui_send, so it also works when Neovim runs in a container inside a Kitty window. The image goes directly in the escape codes, compressed with zlib when the system library is there.
  • Two images per ribbon take turns. The next image loads while the current one stays on screen, so scrolling does not blink.
  • Same blocks as Neovim. With three or four windows, Neovim compares every buffer with the first one and merges overlapping changes into shared blocks. The ribbons copy that merge, so they always match the highlighted lines.

Limitations

  • Needs a terminal with Kitty graphics and Unicode placeholders (Kitty, Ghostty, …), Neovim 0.12+ for nvim_ui_send, and termguicolors. Not inside tmux in my setup.
  • GUIs such as Neovide cannot show it yet. They need image support in the Neovim UI protocol first (neovim/neovim#39434).
  • diffview-plus.nvim.lib.get_current_view() and the layout fields are internal, not a documented API, so a refactor could break the plugin.

lucobellic avatar Nov 21 '26 16:11 lucobellic