-
Notifications
You must be signed in to change notification settings - Fork 756
Vim, Neovim
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:
-
Install the
DirDiffVim plugin. -
Create a script in your
PATHnamedvimdirdiff, 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
# Setting the colorscheme is optional
vim "$@" -c "colorscheme murphy" -c "DirDiff $DIR1 $DIR2"- Make that script executable:
chmod +x vimdirdiff. - In your
.jjconfig.toml, setui.diff-editor="vimdirdiff". - (Optional) You can also create a similar
gvimdirdiffscript. The last line would need to include--nofork:
gvim --nofork "$@" -c "colorscheme murphy" -c "DirDiff $DIR1 $DIR2"-
Make sure you have Python installed. Optionally, check your Python version by running
python --version. -
Install
vimtabdiff.pyas 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
PATHand that you ranchmod +xon it. -
In your
.jjconfig.toml, setui.diff-editor="vimtabdiff.py".
- The UI if
DirDiffis better if you have many files to compare, while thevimtabdiff.pyis 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.
The vim-jjdescription Vim plugin
provides highlighting of .jjdescription files that jj uses to edit commit messages.
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.
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"]The following merge-tool setup can be using to create a temporary parent and current git commit before invoking neovim, allowing you to use existing tooling like sindrets/diffviewiew.nvim, NeogitOrg/neogit, or tpope/vim-fugitive to edit and stage hunks during jj split -i, jj diffedit, etc.
config.toml:
[merge-tools.neovim]
program = "sh"
edit-args = [
"-c",
"""
set -eu
rm -f "$right/JJ-INSTRUCTIONS"
git -C "$left" init -q
git -C "$left" add -A
git -C "$left" commit -q -m baseline --allow-empty # create parent commit
mv "$left/.git" "$right"
git -C "$right" add --intent-to-add -A # create current working copy
(cd "$right"; nvim)
git -C "$right" diff-index --quiet --cached HEAD && { echo "No changes done, aborting split."; exit 1; }
git -C "$right" commit -q -m split # create commit on top of parent including changes
git -C "$right" restore . # undo changes in modified files
git -C "$right" reset . # undo --intent-to-add
git -C "$right" clean -q -df # remove untracked files
"""
]To use, run i.e. jj split -i --tool neovim, stage changes how you normally would in git, then quit neovim.
-
jj-diffconflictsprovides an interface to resolve merge conflicts. It can be configured to be invoked throughjj resolve. -
vcsigns.nvimadds gutter signs and hunk operations for various version control systems, including dedicated support for jj. -
vcmarkers.nvimadds highlighting and operation for various conflict marker styles, but with specialized support for jj's conflict markers (e.g. cycling which side is shown as a snapshot). -
nvim-treesitter-jjconfigprovides syntax highlighting (and other treesitter features) for revset and template expressions in jj configuration files.
-
zschreur/telescope-jj.nvimis a Neovim plugin to provide you with similar behavior to Telescope'sbuiltin.git_filesandbuiltin.git_statusfunctions, as well listing conflicts. -
Cretezy/neo-tree-jj.nvimis a Neovim plugin to provide you with similar behavior to Neo-tree'sgit_statussource. It can add a tab to Neo-tree to display the current status of a jj repo.
You can use AstroCommunity (even without using AstroNvim) to configure several of these plugins at once. Import the jj pack in your Lazy.nvim config:
{
"AstroNvim/astrocommunity",
{ import = "astrocommunity.pack.jj" },
}