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

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

Open
carlpett opened this issue Mar 24, 2024 · 3 comments
Open

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

carlpett opened this issue Mar 24, 2024 · 3 comments

Comments

@carlpett
Copy link

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
Copy link

Seeing the same in delta 0.17.0

@sadamczyk
Copy link

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. 🤷
  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
    format!(
    "^(commit{}{}{}{}{})",
    optional_regexp(file_added_label),
    optional_regexp(file_removed_label),
    optional_regexp(file_renamed_label),
    optional_regexp(file_modified_label),
    optional_regexp(hunk_label),
    )

    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
Copy link
Owner

dandavison commented Jun 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants