How do I tune Vim diff mode for more readable side-by-side hunks?
Answer
:set diffopt+=vertical,algorithm:patience,indent-heuristic
Explanation
Default diff behavior can look noisy on refactors where blocks move or indentation shifts. This diffopt combination improves readability by forcing vertical layout and choosing a diff strategy that better preserves meaningful structure. For large reviews, that often means fewer distracting hunks and clearer intent.
How it works
verticalopens diff windows side-by-side instead of stacked, which is easier for line-by-line scanningalgorithm:patienceuses the patience algorithm, which tends to produce cleaner hunks when lines are reorderedindent-heuristicbiases matching toward indentation-aware boundaries so code blocks line up more naturally
You can apply this on demand before :diffthis, or set it once in your Vim config for a better default review experience.
Example
Given two versions of a function where inner blocks were moved and reindented, default diff may split the change into many small hunks.
Run:
:set diffopt+=vertical,algorithm:patience,indent-heuristic
Then start diff mode; the same change usually appears as fewer, more coherent hunks that are faster to review.
Tips
- You can inspect current settings with
:set diffopt?. - If you need maximum compatibility, append options incrementally and compare output on a real file pair.