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: <leader>gd opens the status explorer,
<leader>gh/<leader>gH the file and branch history, and <leader>gm still
prompts for a base branch and diffs rev...HEAD against it. <leader>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.
This commit is contained in:
Jonny Barnes 2026-08-27 15:42:08 +01:00
commit d4a4c68787
No known key found for this signature in database
4 changed files with 24 additions and 11 deletions

View file

@ -1,34 +0,0 @@
vim.pack.add({ 'https://github.com/sindrets/diffview.nvim' })
require('diffview').setup()
local function map(lhs, rhs, desc)
vim.keymap.set('n', lhs, rhs, { desc = desc })
end
map('<leader>gd', '<Cmd>DiffviewOpen<CR>', 'Diff against index')
map('<leader>gc', '<Cmd>DiffviewClose<CR>', 'Close diff view')
map('<leader>gh', '<Cmd>DiffviewFileHistory %<CR>', 'File history')
map('<leader>gH', '<Cmd>DiffviewFileHistory<CR>', '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.
local function default_branch()
local remote = vim.fn.systemlist('git remote')[1]
if not remote or remote == '' then
return ''
end
local ref = vim.fn.systemlist('git symbolic-ref refs/remotes/' .. remote .. '/HEAD')[1]
if not ref or ref == '' then
return ''
end
return ref:gsub('^refs/remotes/' .. remote .. '/', '')
end
map('<leader>gm', function()
vim.ui.input({ prompt = 'Diff against: ', default = default_branch() }, function(rev)
if rev and rev ~= '' then
vim.cmd('DiffviewOpen ' .. rev .. '...HEAD')
end
end)
end, 'Diff against branch')