Syntax-highlighted diffs in lazygit
Table of Contents
I spend half my day in lazygit. It’s my favorite Git interface, but the out-of-the-box configuration is a little bare-looking. And as a light-mode user, it leaves me staring at black text on red and green backgrounds. Most importantly.. Syntax highlighting is sorely lacking!
git-delta is a diff pager that runs diffs through bat’s syntax definitions, so added and removed code keeps its highlighting.
This is the config that works in a light terminal:
git:
pagers:
- colorArg: always
pager: "delta --light --paging=never --line-numbers --syntax-theme='GitHub' --minus-style='syntax #ffd0d0' --plus-style='syntax #d0ffd0'"Install with brew install git-delta, then check delta --list-languages for your language. Swift is bundled, along with everything else bat highlights.
About those flags:
--paging=neverstops delta from launching its own pager.lazygitalready owns the screen; without this you get a pager inside a pager.--lightand--syntax-theme='GitHub'are two separate systems, and you need both. The first sets delta’s own chrome (file headers, line numbers, the red and green backgrounds). The second colors the code. Set one without the other and you get dark-theme code floating on light backgrounds, or the reverse.- The
--minus-styleoverride’s important: by defaultgit-deltasyntax-highlights added lines but not removed ones, which fall back to plain text on red.syntax #ffd0d0keeps the code colors and paints a pale red background. The plus variant mostly restates delta’s default; I set both so the pair stays symmetric. - No
--side-by-side. Thelazygitdiff pane is too narrow for it.
Quote the pager string
This one fails silently. In YAML, a # preceded by a space starts a comment. Leave the pager line unquoted and everything from #ffd0d0 onward vanishes before delta ever sees it. Wrap the whole value in double quotes and move on.
The config lazygit actually reads
On macOS, lazygit --print-config-dir points at ~/Library/Application Support/lazygit. True, but not the full story: --use-config-file overrides it, and it takes a comma-separated list of files, merged in order, later files winning per key.
That merge is the fun part. My shell wrapper picks configs based on macOS appearance:
lazygit() {
local config="$HOME/.config/lazygit/config.yml"
if [[ "$(defaults read -g AppleInterfaceStyle 2>/dev/null)" != "Dark" ]]; then
config="$config,$HOME/.config/lazygit/theme-light.yml"
fi
command lazygit --use-config-file="$config" "$@"
}The base config carries a dark pager:
# config.yml
git:
pagers:
- colorArg: always
pager: delta --dark --paging=never --line-numbersThe light overlay flips lazygit’s theme and swaps the pager:
# theme-light.yml
gui:
theme:
lightTheme: true
git:
pagers:
- colorArg: always
pager: "delta --light --paging=never --line-numbers --syntax-theme='GitHub' --minus-style='syntax #ffd0d0' --plus-style='syntax #d0ffd0'"My terminal follows the system appearance, and lazygit and delta follow the terminal. The diffs stay syntax-highlighted either way.