Make diff highlight closer to git/github
When doing diffs of files, (Neo)vim has the behavior of showing the added/deleted lines compared to the other file, BUT in git/github' side-by-side view will instead only show deleted lines on the old file and new lines on the new file (+ changes in both if any).
To make Neovim work this way we can leverage winhighlight to change the diff-related highlight groups for a given window only.
Got the hint at:
https://github.com/neovim/neovim/discussions/27512#discussioncomment-8503891
And with some tweaks we can go a little further and have this:
:heart:
Since this changes the highlights locally to a window, it could give unexpected highlights if changing/swapping buffer in same window, moving windows... Still it would be nice to have (with hooks to disable the highlight changes to avoid unexpected hl).
Since (Neo)vim doesn't have any knowledge of the old file / current file we'd need to use different commands to mark the old/current file so highlights are changed correctly..
" Set deleted line filler char to a space, to hide them
setlocal fillchars+=diff:\
" On the old file we need:
setlocal winhighlight=DiffDelete:Normal,DiffAdd:DiffDelete,DiffText:DiffDelete
" => Don't show added lines (use 'Normal' hl)
" => Show lines that are not in new/current file as deleted
" => Changed text in a line is _old_ text
" On the new/current file we need:
setlocal winhighlight=DiffDelete:Normal,DiffText:DiffAdd
" => Don't show deleted lines (use 'Normal' hl)
" => Changed text in a line is _new_ text
NOTE: using Normal hl isn't perfect because it's not 'dynamic' when NormalNC is used to set a different bg color for non-current windows, making the deleted line standout a little on non-current window.
👉 Alternative is to create a dummy hl group like hi Test ctermbg=none ctermfg=none and use it instead of Normal.