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:
parent
2f1cd1a1c3
commit
d4a4c68787
4 changed files with 24 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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; <leader>gc is here too so the
|
||||
-- same key that opened things from the g/diff group also shuts them.
|
||||
view = { quit = { 'q', '<leader>gc' } },
|
||||
},
|
||||
})
|
||||
|
||||
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')
|
||||
map('<leader>gd', '<Cmd>CodeDiff<CR>', 'Diff working tree')
|
||||
map('<leader>gh', '<Cmd>CodeDiff history %<CR>', 'File history')
|
||||
map('<leader>gH', '<Cmd>CodeDiff history<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.
|
||||
|
|
@ -28,7 +33,9 @@ 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')
|
||||
-- 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')
|
||||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue