dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
21.34k stars 359 forks source link

🐛 --navigate n/N jumps to next/prev hunk, not file? #1666

Open carlpett opened 3 months ago

carlpett commented 3 months ago

Possibly a misunderstanding? But when I turn on navigation, do git diff and press n, the screen advances to the next hunk, even if it is in the same file.

I'm using delta 0.16.5, from Fedora repos. Running inside tmux on Alacritty, if that is relevant.

jasonmobley commented 1 month ago

Seeing the same in delta 0.17.0

sadamczyk commented 1 month ago

I'm a bit annoyed by this as well. Jumping to the next hunk is usually such a small jump that scrolling with Ctrl+D/U already is more than good enough. And it's especially annoying with large files like lock files.

But this behavior is documented in the Features list of the README.md (even though it's missing from the docs):

n and N keybindings to move between files in large diffs, and between diffs in log -p views (--navigate)

There are 2 options to fix this:

  1. Set --hunk-label "" to an empty string. Or via ~/.gitconfig: hunk-label = (just nothing). This removes the from the beginning of every hunk, but that's totally fine for me. :shrug:
  2. Set the --navigate-regex value to not search for the hunk labels. ~/.git/config: navigate-regex = ^(commit|added:|removed:|renamed:|Δ) But this assumes that you didn't change any of the configs that go into navigate-regex by default, like --file-added-label etc, since navigate-regex is actually built from all those options, see https://github.com/dandavison/delta/blob/0f8a2f0786d56e9395b7e7f244f356bfdab562e8/src/features/navigate.rs#L51-L58 So if you ever change any of these options, you'll need to manually change the navigate-regex option to reflect that as well. Otherwise this seems like the cleanest option.
dandavison commented 1 month ago

Just want to say that I sympathise with this! I also find that if I'm using navigate to jump, then by-hunk jumps often feel too small. So I'm open to interface design change proposals here.

A related variant is to increase our diff context, i.e. with git ... -U99 | delta or

[diff]
    context = 99

If we set that number large enough, then there are no within-file hunks any longer hence navigate jumps become by-file! Of course it can sometimes not be exactly what you want to have to scroll past large sections of unchanged content, but sometimes the lack of hunk breaks makes diffs easier to understand.

sadamczyk commented 3 weeks ago

@dandavison Good idea with setting a wider context. I'll definitely play around with increasing it a bit, even though 99 seems way too high for me personally. I'll set it to 9 and see how I like it, which will still reduce some hunks hopefully.

IMO The best way would be to have multiple search patterns, that you can search via different hotkeys. For example something like n / N just for hunk jumps, c / C for commits, f / F for files etc. That way the user can use whatever jumps make the most sense for their current use case. But since delta uses plain old less, this isn't really possible afaik.

I could almost emulate this behavior with custom terminal hotkeys (I use WezTerm), so that my terminal inputs the correct search pattern for whatever navigation "mode" I want to use. So for example pressing Ctrl+Shift+H could send the following key strokes to the terminal and therefore set less' search pattern to "hunks only": /^(•)↵ And then just use n/N as always. And then have other hotkeys for other common navigation/search patterns I use.