Skip to content

Instantly share code, notes, and snippets.

@ilyagr
Last active April 30, 2023 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyagr/5d6339fb7dac5e7ab06fe1561ec62d45 to your computer and use it in GitHub Desktop.
Save ilyagr/5d6339fb7dac5e7ab06fe1561ec62d45 to your computer and use it in GitHub Desktop.
Using Vim as a `jj` difftool with the DirDiff plugin or vimtabdiff.py script

vimdiff comes as a pre-configured merge tool for jj and can be used with jj resolve out of the box. However, the default configuration for vimdiff as a diff editor (for jj split, etc.) is barely useable.

To more conveniently use Vim as a difftool for jj, try one of the following setups:

DirDiff plugin

  1. Install the DirDiff Vim plugin.

  2. Create a script in your PATH named vimdirdiff, with the following contents:

#!/bin/bash
# On Mac OS, you may need to replace `/bin/bash` with `/bin/zsh`.

# Shell-escape each path:
DIR1=$(printf '%q' "$1"); shift
DIR2=$(printf '%q' "$1"); shift
# The colorscheme is only important on Vim versions older than 9.0
vim "$@" -c "colorscheme murphy | DirDiff $DIR1 $DIR2"
  1. Make that script executable: chmod +x vimdirdiff.
  2. In your .jjconfig.toml, set ui.diff-editor="vimdirdiff".

vimtabdiff.py script

  1. Make sure you have Python installed. Optionally, check your Python version by running python --version.

  2. Install vimtabdiff.py as described here. Use the command for python <3.10 if you are not sure what your version of Python is.

    Make sure it is in your PATH and that you ran chmod +x on it.

  3. In your .jjconfig.toml, set ui.diff-editor="vimtabdiff.py".

Pros and cons of DirDiff/vimtabdiff.py

  • The UI if DirDiff is better if you have many files to compare, while the vimtabdiff.py is better for fewer files
  • vimtabdiff.py requires having Python installed, while DirDiff doesn't.
  • DirDiff requires installing a Vim plugin, while vimtabdiff.py doesn't.

More advanced vimtabdiff instructions (explanation, testing TODO)

curl "https://raw.githubusercontent.com/balki/vimtabdiff/br-py38/vimtabdiff.py"
# In .jjconfig.toml
ui.diff-editor = ["python3", "path/to/vimtabdiff.py", "--", "--vim", '''vim -c "colorscheme murphy"''', "$left", "$right"]

Pros and cons of DirDiff/vimtabdiff.py

  • vimtabdiff.py may be easier to get to work on Windows (TODO: double-check)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment