Skip to content

Conversation

@KJ7LNW
Copy link

@KJ7LNW KJ7LNW commented Jan 15, 2026

Description

Adds runtime toggle for word-level diffs using git's --color-words flag. Complements existing whitespace toggle by providing finer-grained diff visualization.

Example

The code in this example is out of context, but it shows how word-level diffing can be used to see what actually changed. This is a sample of what it looks like in lazy git when you apply the word level change and enable it:

image

Type of Change

  • Feature (non-breaking change that adds functionality)

Implementation Details

Mirrors whitespace toggle architecture:

  • Config field git.colorWordsInDiffView (default: false)
  • Controller toggle_color_words_action.go with context exclusions for staging/patch-building
  • Keybinding <c-x> registered in global_controller.go
  • Git commands: added --color-words flag conditionally to diff, show, and stash show commands
  • UI: subtitle displays active modes: "(ignoring whitespace) | (color words)"

Both flags can be enabled simultaneously in git commands without conflict.

Testing

  • Tests pass locally (all 72 unit test packages)
  • Build successful

Enable users to toggle word-level diffs (git --color-words) from within
the application without modifying config files. This provides a more
granular view of changes for detailed code review by highlighting
word-level modifications instead of full-line diffs.

- add ColorWordsInDiffView config option to track state across sessions
- add --color-words flag to all diff command builders (commit, diff, stash, working tree)
- add Ctrl+X keybinding to toggle color-words mode
- prevent toggling in staging contexts where word-level diffs are unsupported
- show "(color words)" subtitle indicator when mode is active
- add translations for keybinding, tooltip, subtitle, and error message

Signed-off-by: Eric Wheeler <lazygit@z.ewheeler.org>
@stefanhaller
Copy link
Collaborator

@KJ7LNW Thanks, but this has come up before, and I don't want to add this. See #5147 and #4921 for discussion.

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