From d4a4c687874aa5f953986015e73e5f88f492be00 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Thu, 27 Aug 2026 15:42:08 +0100 Subject: [PATCH] Replace diffview.nvim with codediff.nvim diffview was doing the job for reviewing a branch before merging it, but not well enough. codediff renders diffs the way VSCode does - light line-level backgrounds with deeper character-level highlights on top of them - so what actually changed within a line is legible rather than inferred. Keymaps carry over one for one: gd opens the status explorer, gh/gH the file and branch history, and gm still prompts for a base branch and diffs rev...HEAD against it. gc is folded into codediff's own quit action alongside q, since there is no close command to map it to. Its diffing is done in C, and the library is downloaded prebuilt on first use rather than compiled, so there is no build step for vim.pack to worry about. --- neovim/README.md | 6 ++++++ .../plugins/{diffview.lua => codediff.lua} | 21 ++++++++++++------- neovim/config/plugins/init.lua | 2 +- neovim/nvim-pack-lock.json | 6 +++--- 4 files changed, 24 insertions(+), 11 deletions(-) rename neovim/config/plugins/{diffview.lua => codediff.lua} (53%) diff --git a/neovim/README.md b/neovim/README.md index 57f4af4..aa6f6e4 100644 --- a/neovim/README.md +++ b/neovim/README.md @@ -37,6 +37,12 @@ machine gets the same set. > nvim-web-devicons needs a Nerd Font in the terminal or the icons render as > tofu. `brew.sh` installs one for ghostty. +> [!NOTE] +> codediff.nvim does its diffing in C. It downloads a prebuilt library into its +> own plugin directory on first use — so the first `:CodeDiff` on a new machine +> needs network, and the binary is not covered by the lock file. `:CodeDiff +> install!` forces a re-download if it ever goes missing or stale. + ## Defaults worth knowing - **The colorscheme is catppuccin**, `flavour = 'auto'`: latte on a light diff --git a/neovim/config/plugins/diffview.lua b/neovim/config/plugins/codediff.lua similarity index 53% rename from neovim/config/plugins/diffview.lua rename to neovim/config/plugins/codediff.lua index 0f7befd..80775fe 100644 --- a/neovim/config/plugins/diffview.lua +++ b/neovim/config/plugins/codediff.lua @@ -1,15 +1,20 @@ -vim.pack.add({ 'https://github.com/sindrets/diffview.nvim' }) +vim.pack.add({ 'https://github.com/esmuellert/codediff.nvim' }) -require('diffview').setup() +require('codediff').setup({ + keymaps = { + -- q closes the diff tab from inside it; gc is here too so the + -- same key that opened things from the g/diff group also shuts them. + view = { quit = { 'q', 'gc' } }, + }, +}) local function map(lhs, rhs, desc) vim.keymap.set('n', lhs, rhs, { desc = desc }) end -map('gd', 'DiffviewOpen', 'Diff against index') -map('gc', 'DiffviewClose', 'Close diff view') -map('gh', 'DiffviewFileHistory %', 'File history') -map('gH', 'DiffviewFileHistory', 'Branch history') +map('gd', 'CodeDiff', 'Diff working tree') +map('gh', 'CodeDiff history %', 'File history') +map('gH', 'CodeDiff history', 'Branch history') -- The base branch name varies per repo (main, master, develop, ...), so ask -- the first remote's HEAD what it is rather than hardcoding one. @@ -28,7 +33,9 @@ end map('gm', function() vim.ui.input({ prompt = 'Diff against: ', default = default_branch() }, function(rev) if rev and rev ~= '' then - vim.cmd('DiffviewOpen ' .. rev .. '...HEAD') + -- rev...HEAD is merge-base semantics: what this branch added, not what + -- the base branch has moved on to since. + vim.cmd('CodeDiff ' .. rev .. '...HEAD') end end) end, 'Diff against branch') diff --git a/neovim/config/plugins/init.lua b/neovim/config/plugins/init.lua index 7046983..ea9535b 100644 --- a/neovim/config/plugins/init.lua +++ b/neovim/config/plugins/init.lua @@ -1,6 +1,6 @@ -- The colorscheme goes first so everything after it is drawn with it applied require('config.plugins.catppuccin') -require('config.plugins.diffview') +require('config.plugins.codediff') require('config.plugins.fzf-lua') require('config.plugins.gitsigns') require('config.plugins.nvim-tree') diff --git a/neovim/nvim-pack-lock.json b/neovim/nvim-pack-lock.json index c80ef95..9508372 100644 --- a/neovim/nvim-pack-lock.json +++ b/neovim/nvim-pack-lock.json @@ -4,9 +4,9 @@ "rev": "edefef779ab08ce1a4a404713e3012b0d202bd35", "src": "https://github.com/catppuccin/nvim" }, - "diffview.nvim": { - "rev": "4516612fe98ff56ae0415a259ff6361a89419b0a", - "src": "https://github.com/sindrets/diffview.nvim" + "codediff.nvim": { + "rev": "e08a35a56a52c290398ebfaec33c34cfcf2d0f3c", + "src": "https://github.com/esmuellert/codediff.nvim" }, "fzf-lua": { "rev": "8671012a7b2a1648595952c655039d51fb301c14",