# gap

A small native GUI utility for diffing text. Point it at two files (or two directories) and it renders the differences the way a pull-request view on GitHub or Azure DevOps would — a graphical, colorized side-by-side, not a terminal pager over unified-diff text. Written by Cameron DaCamara (cdacamar), an MSVC compiler engineer, during the Handmade Essentials 2026 Jam.

The project has two stated goals. The obvious one is a simple, self-contained diff viewer with no dependencies beyond a C++ compiler. The real motivation is the second one: gap is a proof-of-concept for the linear-space variant of the Myers diff algorithm, which the author plans to fold into his editor [fred](https://fred-dev.tech). So gap is less a finished tool and more a testbed for the diff engine that goes somewhere else.

## What Myers linear does here

The Myers algorithm computes the shortest edit script between two sequences — the minimal set of insertions and deletions that turns one file into the other. That's the standard diff problem (longest common subsequence), and it's a different thing from the edit-distance / fuzzy-match work in [[levenshtein-trie]], which finds dictionary words within N edits. gap uses the linear-space refinement of Myers so memory stays proportional to input size rather than to the product of the two file lengths, which matters when you diff large files inside an interactive editor.

On top of the line-level diff, gap can compute inner-diffs within blocks that look similar, highlighting the changed region word-by-word or character-by-character.

## Features

- Word-based and character-based inner-diffs inside changed blocks.
- Swap the two sides of a diff with one keypress.
- Expand/collapse the context window around changes; a negative value means infinite context (whole file).
- Directory diffing — files in one directory are matched against files in the other.
- A configuration explorer (shared with fred) for line numbers, colors, and disabling animations.
- Help panel with hotkey rebinding.
- Subpixel font rendering, on by default.
- On Windows, a choice of DX11 (default) or OpenGL renderers.

## Usage

```
$ gap a.txt b.txt   # file diff
$ gap ./A ./B       # directory diff
```

Or launch it and drag-and-drop files or directories onto each panel. It also wires into git as a difftool:

```
$ git config difftool.gap.path "D:/git_projects/gap/build/gap.exe"
$ git config difftool.gap.cmd "D:/git_projects/gap/build/gap.exe \"\"\"$LOCAL\"\"\" \"\"\"$REMOTE\"\"\"\""
$ git config diff.tool gap
```

After that, `git difftool` opens gap instead of the default, and `git difftool -d` uses the directory-diff view. This is the same integration point [[delta]] plugs into on the terminal side — delta is a syntax-highlighting pager for `git diff` output, whereas gap is a standalone windowed viewer you register as the difftool.

## Building

No external dependencies on Windows: open a VS2022 (or later) x64 Developer Command Prompt and run `build` (or `build release`). On Linux you need a recent gcc (the author used 13.3.0) plus OpenGL, X11, Xext, and Xrandr dev headers, then `./build.sh`.

## Limitations

- Windows and Linux only — no macOS.
- Jam-scale proof-of-concept by a single author; the diff engine is the point, the UI is a demo shell for it.
- Not a merge tool, review tool, or editor — just a two-sided viewer.

This is on the [[toolbox/watchlist]] — experimental single-author project whose real future is as a component inside fred rather than as a standalone product.

## Repo

[github.com/cdacamar/gap](https://github.com/cdacamar/gap) — C++, MIT, 60 stars.
