Skip to content

Add word-diffing support#5784

Closed
pogoba wants to merge 2 commits into
jesseduffield:masterfrom
pogoba:word-diff
Closed

Add word-diffing support#5784
pogoba wants to merge 2 commits into
jesseduffield:masterfrom
pogoba:word-diff

Conversation

@pogoba

@pogoba pogoba commented Jul 9, 2026

Copy link
Copy Markdown

PR Description

Press ctrl+g to toggle the patch view between show diffs line-wise vs word-wise. Similarly to the ctlr+w ignore-whitespace toggle, the word-diff state is shown alongside the (ignoring whitespace) status flag.

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

This PR is a draft because the PR checklist is incomplete. The main code has undergone human review, but the tests have not.

This PR is potentially a duplicate of:

pogoba and others added 2 commits July 7, 2026 20:07
Line-level diffs make small in-word edits hard to spot: a one-word
change renders as a whole line removed and re-added. Git's
`--word-diff=color` highlights the changed words inline instead, which
is much easier to read for prose and for dense single-line changes.

Model it on the existing `<ctrl+w>` whitespace toggle rather than a
per-view binding: it's a global keybinding (`<ctrl+g>`) that flips an
in-memory config flag which the diff-building commands (working-tree
diff, `git show`, stash show, file diffs) consult when rendering, so it
works from any diff without first focusing the main view. The staging
and patch-building views are excluded, sharing one unsupported-context
list with the whitespace toggle, because word-diff collapses the +/-
lines that line-by-line staging depends on.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The main diff view already advertised `(ignoring whitespace)` in its
subtitle when that mode was on. Now that word-diff is a second toggle
that changes how the same diff is rendered, generalize that single-mode
subtitle into one that lists every active option, so `<ctrl+g>` gets the
same at-a-glance feedback `<ctrl+w>` has.

Rename the whitespace-specific helper to `DiffViewSubtitle` and have it
join the active tags (`(ignoring whitespace) (word diff)`); every diff
view already routed its subtitle through the one helper, so they all
pick up the word-diff tag without further changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stefanhaller

Copy link
Copy Markdown
Collaborator

See here for why I don't want this: #5209 (comment)

Besides, this project does not accept PRs anyway, see CONTRIBUTING.md.

@pogoba

pogoba commented Jul 9, 2026

Copy link
Copy Markdown
Author

I see. I'm not familiar with the "different pagers" feature yet, but i will look into it.

Do you think it makes sense to ship one or two common git diff based pager scripts directly with a default lazygit installation?

@pogoba pogoba closed this Jul 9, 2026
@stefanhaller

Copy link
Copy Markdown
Collaborator

Do you think it makes sense to ship one or two common git diff based pager scripts directly with a default lazygit installation?

Personally I don't think so. I find actual pagers vastly superior to --word-diff/--color-words. I personally use delta as the default pager, it does a pretty good job at highlighting word changes, and in those few cases where it doesn't I switch to difftastic on demand.

@pogoba

pogoba commented Jul 9, 2026

Copy link
Copy Markdown
Author

At least we could add the git diff --work-diff config example to https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md ?

Config example: #4921 (comment)

@stefanhaller

Copy link
Copy Markdown
Collaborator

Makes sense, #5795.

stefanhaller added a commit that referenced this pull request Jul 10, 2026
…lazygit (#5795)

Since this frequently comes up as a feature request (but there are
reasons why we don't want to add it), explain how to do this in lazygit
today.

See
#5784 (comment).
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

Successfully merging this pull request may close these issues.

2 participants