vimtricks.wiki Concise Vim tricks, one at a time.

How do I enable inline character-level diff highlighting in Neovim's diff mode?

Answer

:set diffopt+=linematch:60

Explanation

Neovim's linematch diffopt enables intra-line diff highlighting — instead of marking an entire changed line, Neovim highlights only the specific characters that differ. Stock diff mode highlights the full line regardless of how small the change is; linematch makes diffs dramatically more readable for small edits like variable renames or single-word tweaks.

How it works

  • linematch:{N} sets the maximum character-difference threshold for inline matching. If two changed lines differ by fewer than N characters, Neovim highlights only the changed characters.
  • A value of 60 is a practical default that covers most common edits (renamed identifiers, changed literals, swapped operators) without performance overhead.
  • This option is Neovim-specific (0.9+) and is not available in stock Vim.

Example

Changing a line from:

local response_count = 0

to:

local request_count = 0

Without linematch, the entire line is highlighted as changed. With linematch:60, only response and request are highlighted, making the diff instantly readable.

Tips

  • Combine with the patience algorithm and indent heuristic for best overall diff quality:
set diffopt+=algorithm:patience,indent-heuristic,linematch:60
  • Increase the threshold (e.g., linematch:100) for files with very long lines.
  • Use :h diff-linematch in Neovim to read about the algorithm details.
  • This setting pairs well with diff plugins like diffview.nvim, which also respects diffopt.

Next

How do I change the working directory to the folder containing the current file without affecting other windows?