A tool for splitting diffs in Neovim
This is a Neovim tool for splitting/editing diffs. It operates over a left
and right
directory, producing a diff of
the two which can subsequently be inspected and modified. The DiffEditor
allows selecting changes by file, hunk or
individual line to produce a new partial diff.
This was primarily built to be used with jujutsu as an alternative diff-editor to
it's :builtin
option, but it's designed generically enough that it can be used for other use cases.
To use it you need to give it two to three directories: a left
, a right
, and optionally a output
directory. These
directories will then be read in and used to produce a set of diffs between the two directories. You will then be
presented with the left and right side of each file and can select the lines from each diff hunk you would like to keep.
When you are happy with your selection you can accept changes and the diff editor will modify the output
directory (or
the right
directory if no output is provided) to match your selection.
Using folke/lazy.vim
{
"julienvincent/hunk.nvim",
cmd = { "DiffEditor" },
config = function()
require("hunk").setup()
end,
}
- nui.nvim
- nvim-web-devicons (optional)
- mini.icons (optional)
If you want file type icons in the file tree then you should have one of either mini.icons
or nvim-web-devicons
installed. Otherwise, neither are required.
local hunk = require("hunk")
hunk.setup({
keys = {
global = {
quit = { "q" },
accept = { "<leader><Cr>" },
focus_tree = { "<leader>e" },
},
tree = {
expand_node = { "l", "<Right>" },
collapse_node = { "h", "<Left>" },
open_file = { "<Cr>" },
toggle_file = { "a" },
},
diff = {
toggle_line = { "a" },
toggle_hunk = { "A" },
},
},
ui = {
tree = {
-- Mode can either be `nested` or `flat`
mode = "nested",
width = 35,
},
},
icons = {
selected = "",
deselected = "",
folder_open = "",
folder_closed = "",
},
})
Jujutsu is an alternative VCS that has a focus on working with individual commits and their diffs.
A lot of commands in jujutsu allow you to select parts of a diff. The tool used to select the diff can be configured via
their ui.diff-editor
config option. To use hunk.nvim
add the following to your jujutsu config.toml
:
[ui]
diff-editor = ["nvim", "-c", "DiffEditor $left $right $output"]
You can find more info on this config in the jujutsu docs.