ymattw / ydiff

View colored, incremental diff in workspace or from stdin, side by side and auto paged.
Other
877 stars 62 forks source link

Navigate to next hunk #114

Closed rj-jesus closed 5 months ago

rj-jesus commented 1 year ago

Hi,

Not an issue per se, but is there a way to navigate/move to the next hunk of diff? I sometimes work with very large diff files where only a few lines have changed, it would be extremely useful if I could navigate to those lines quickly. Any idea how this could be done?

Thanks very much!

-Ricardo

5HT2 commented 5 months ago

You might find this issue helpful: https://github.com/jonas/tig/issues/1005

Essentially, use /^@@ to match a hunk, use n for next match, N for previous match,gg` to go to top.

You can also use /^diff for the start of an individual file in a larger diff.

I'm unsure if ydiff has a way to bind these keybindings, however, but I would love to know if there is.

5HT2 commented 5 months ago

Found a solution!

  1. Create a file called ~/.lesskey with the contents:

    #command
    e noaction /\^\@\@\r
  2. Now, you will also want to set an env var:

    export LESSKEY="~/.lesskey"
    • If you are on macOS, you will need to replace your system-provided less with one built from source, use brew install less, and ensure that you have them both in your PATH:
      $ which less lesskey
      /opt/homebrew/bin/less
      /opt/homebrew/bin/lesskey
  3. Do NOT use -k to specify the lesskey file, do NOT name the file anything other than ~/.lesskey. You also do not need to use lesskey to compile the ~/.lesskey file to anything, do not touch the lesskey command itself, you're just verifying it exists to ensure your less version supports binding keys.

  4. Now, run ydiff, use e to match a hunk, press n for next match, N for previous match.

ymattw commented 5 months ago

Thanks for the tips @5HT2. Ydiff will not support the requests since the interaction is handled by the pager program (less by default).