Re: [PATCH] add -p: introduce 'w' command to view hunk with --word-diff
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- May 7, 2026, 14:39 UTC
- Message-ID
- <CALnO6CCsOMyLxAhGW10L4duaahUORwedfmtdpY3zDGpQcZoP2Q@mail.gmail.com>
- In-Reply-To
- <e640ac2d-9e46-4f1e-9aef-deac80c65361@gmail.com>
On Thu, May 7, 2026 at 9:28 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 17 quoted lines
> > Hi Javier > > On 07/05/2026 00:54, Javier Bassi wrote: > > When using `git add --patch`, reviewing changes in long lines can be > > difficult with the default line-based diff. This is particularly > > noticeable in formats such as JSONP, CSV, LaTeX, Markdown, or other > > plain text where small inline edits can be hard to spot. > > > > Added `w - print the current hunk with word-diff` during hunk selection > > to re-display the current hunk using `--word-diff`. This provides a > > clearer inline view of changes without modifying the hunk or affecting > > how patches are applied or staged. > > I think this is useful. While one can set interactive.diffFilter to > highlight intraline differences with "diff-highlight" or "delta" they do > not cope well if the text has been reflowed.
I concur, though I wonder what other diff options would be useful. I can imagine a world where "add --patch" allows to reshow the patch with any set of custom options. Spitballing…
:show <opts>
…could work, since we have room to allow long-form commands still. This could be extended to arbitrary git-* commands, and ":!cmd" could be used for shelling out.
(Can you tell I use Vim?)
Anyway, what I like about this is we don't have to worry about running out of (or thinking up new mnemonics for) single letters for different combinations of diff options, so it's a bit more extensible.
Show 13 quoted lines
> I think the approach of using the current hunk text, rather than running > "git diff --diff-words" is sensible because it works correctly if the > user has edited the hunk and it makes it easy to handle hunks that have > been split. It would be good to propagate the filename when creating the > filespec so that we use the correct word diff regex for the file. We > should also propagate the context and inter-hunk context settings from > struct interactive_options. It would also be a good idea to reuse the > hunk header from the unified diff so that the line numbers and hunk > fragment are correct. > > Thanks > > Phillip
-- D. Ben Knoble