Skip to content
Cretezy edited this page May 24, 2024 · 10 revisions

Using Vim as a diff tool

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.

Syntax highlighting for editing commit descriptions

The vim-jjdescription Vim plugin provides highlighting of .jjdescription files that jj uses to edit commit messages.

Neovim

Using Neovim as editor

You can set Neovim to be your editor for describe and other commands with the following config:

ui.editor = "nvim"

This pairs well with vim-jjdescription Vim plugin as described above.

Using with flatten.nvim

flatten.nvim allows you to un-nest Neovim instances. For example, running jj describe in a :terminal will open in the parent Neovim instance.

jj expects the editor to wait until the file is closed to save. This can be achieved by using:

ui.editor = ["nvim", "--cmd", "let g:flatten_wait=1"]

Telescope Extension

zschreur/telescope-jj.nvim is a Neovim plugin to provide you with similar behavior to Telescope's builtin.git_files and builtin.git_status functions, as well listing conflicts.

Neo-tree Extension

Cretezy/neo-tree-jj.nvim is a Neovim plugin to provide you with similar behavior to Neo-tree's git_status source. It can add a tab to Neo-tree to display the current status of a jj repo.

AstroNvim/AstroCommunity

You can use AstroCommunity (even without using AstroNvim) to configure all these plugins at once. Import the jj pack in your Lazy.nvim config:

{
  "AstroNvim/astrocommunity",
  { import = "astrocommunity.pack.jj" },
}
Clone this wiki locally