Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make diff highlight closer to git/github #94

Open
bew opened this issue Feb 18, 2024 · 0 comments
Open

Make diff highlight closer to git/github #94

bew opened this issue Feb 18, 2024 · 0 comments
Labels
kind:enhancement New feature or request

Comments

@bew
Copy link
Owner

bew commented Feb 18, 2024

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:
neovim/neovim#27512 (reply in thread)

And with some tweaks we can go a little further and have this:
Image
❤️

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.

@bew bew added for:editor kind:enhancement New feature or request and removed for:editor labels Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:enhancement New feature or request
Projects
Development

No branches or pull requests

1 participant