feat(fugitive): add status buffer keymaps for unified diffs

Adds du/dU keymaps to fugitive's :Git status buffer for opening unified
diffs instead of side-by-side diffs:
- du opens horizontal split (mirrors dd)
- dU opens vertical split (mirrors dv)

Parses status buffer lines to extract filename and detect section
(staged/unstaged/untracked). For staged files, diffs index vs HEAD.
For unstaged files, diffs working tree vs index.

Configurable via vim.g.diffs.fugitive.horizontal/vertical (set to
false to disable).
This commit is contained in:
Barrett Ruth 2026-02-04 22:23:21 -05:00
parent ea60ab8d01
commit 9289f33639
3 changed files with 186 additions and 0 deletions

View file

@ -12,11 +12,16 @@
---@field treesitter diffs.TreesitterConfig
---@field vim diffs.VimConfig
---@class diffs.FugitiveConfig
---@field horizontal string|false
---@field vertical string|false
---@class diffs.Config
---@field debug boolean
---@field debounce_ms integer
---@field hide_prefix boolean
---@field highlights diffs.Highlights
---@field fugitive diffs.FugitiveConfig
---@class diffs
---@field attach fun(bufnr?: integer)
@ -78,6 +83,10 @@ local default_config = {
max_lines = 200,
},
},
fugitive = {
horizontal = 'du',
vertical = 'dU',
},
}
---@type diffs.Config
@ -219,6 +228,25 @@ local function init()
end
end
if opts.fugitive then
vim.validate({
['fugitive.horizontal'] = {
opts.fugitive.horizontal,
function(v)
return v == false or type(v) == 'string'
end,
'string or false',
},
['fugitive.vertical'] = {
opts.fugitive.vertical,
function(v)
return v == false or type(v) == 'string'
end,
'string or false',
},
})
end
if opts.debounce_ms and opts.debounce_ms < 0 then
error('diffs: debounce_ms must be >= 0')
end
@ -354,4 +382,10 @@ function M.detach_diff()
end
end
---@return diffs.FugitiveConfig
function M.get_fugitive_config()
init()
return config.fugitive
end
return M