syntax-diff-editor is a terminal-based diff and merge tool with semantic navigation powered by tree-sitter. It provides an interactive interface for reviewing and selecting changes, with the ability to navigate by code structure (functions, classes, methods) rather than just diff hunks.
Think of this as an enhanced interactive replacement for git add -p or hg crecord/hg commit -i, with syntax-aware navigation. Given a set of changes, this tool presents them in an interactive interface where you can:
- Navigate through files, functions, and individual changes
- Select/deselect changes at any granularity (files, sections, or individual lines)
- Review changes with syntax highlighting
- Navigate by semantic structure using tree-sitter
- Semantic Navigation: Navigate by code structure (functions, classes, methods) using tree-sitter integration, not just diff hunks
- Flexible Selection: Toggle individual lines, entire sections, or whole files
- Keyboard-Driven: Vim-like keybindings for efficient navigation and selection
- Mouse Support: Click to focus, scroll to navigate
- Universal Compatibility: Works as a difftool or mergetool with any source control system
Important Note: syntax-diff-editor represents a significant change from the original scm-diff-editor project. The original scm-diff-editor (and the underlying scm-record library) is an absolutely wonderful piece of work. The tree-based selection approach for navigating and selecting changes is ergonomically brilliant - it makes reviewing and staging changes feel natural and intuitive in a way that's hard to describe until you experience it.
This fork exists primarily as an experiment: I was so impressed with the elegance of the tree selection interface that I wanted to explore enhancing it with semantic/syntax-aware navigation via tree-sitter. The rename to syntax-diff-editor reflects this focus on syntax-driven navigation, allowing you to navigate your diffs by functions, classes, and methods rather than just by hunks.
All credit for the core design and implementation goes to the original authors. This is merely an exploration of "what if we could navigate by code structure too?" built on top of their excellent foundation.
Original Project: arxanas/scm-record
Install directly from the git repository:
cargo install --git https://github.com/jakeswenson/syntax-diff-editor.git syntax-diff-editorOr install from crates.io once published:
cargo install --locked syntax-diff-editorThe syntax-diff-editor executable can be used with:
- Git: as a difftool or mergetool
- Mercurial: via the
extdiffextension - Any source control system that supports external diff/merge tools
# Compare two files
syntax-diff-editor file1.txt file2.txt
# Compare two directories (auto-detected)
syntax-diff-editor dir1/ dir2/
# Compare two directories (explicit flag)
syntax-diff-editor --dir-diff dir1/ dir2/Note: Directory mode is automatically detected when both paths are directories. You can use the --dir-diff flag to make the behavior explicit or for use in scripts.
Example Git configuration:
# Set as difftool
git config --global diff.tool syntax-diff-editor
git config --global difftool.syntax-diff-editor.cmd 'syntax-diff-editor "$LOCAL" "$REMOTE"'
# Use it
git difftoolsyntax-diff-editor provides a rich set of keyboard shortcuts for efficient navigation and selection. Key bindings include:
- Navigation:
j/k(or arrow keys) for up/down,h/lfor in/out of hierarchy - Selection:
Spaceto toggle,Enterto toggle and advance,afor select/deselect all - Commit:
cto accept changes,eto edit commit message,qto quit
For a complete list of keyboard shortcuts and navigation tips, see the Keyboard Controls documentation.
Contributions are welcome! Here are some areas where syntax-diff-editor could be improved:
- Improve semantic navigation for more languages (expand tree-sitter language support)
- Make keybindings easier to discover
- Support accessing the menu with the keyboard
- Edit one side of the diff in an editor
- Multi-way split UI to split a commit into more than 2 commits
- Full mergetool support with conflict resolution commands
- Commands to select ours/theirs for merge conflicts
- Keyboard Controls - Complete reference for all keyboard shortcuts
- ADR: Tree-sitter Integration - Design decisions for semantic navigation
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.