2023-05-06 19:58:30 +02:00
|
|
|
local gitsigns = require("gitsigns")
|
2022-04-20 14:01:00 +02:00
|
|
|
local wk = require("which-key")
|
2022-03-03 22:15:26 +01:00
|
|
|
|
2024-07-12 20:52:03 +02:00
|
|
|
--- Transform `f` into a function which acts on the current visual selection
|
|
|
|
local function make_visual(f)
|
|
|
|
return function()
|
|
|
|
local first = vim.fn.line("v")
|
|
|
|
local last = vim.fn.line(".")
|
|
|
|
f({ first, last })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-03 22:15:26 +01:00
|
|
|
gitsigns.setup({
|
|
|
|
current_line_blame_opts = {
|
|
|
|
-- Show the blame quickly
|
|
|
|
delay = 100,
|
|
|
|
},
|
2022-04-20 14:01:00 +02:00
|
|
|
})
|
2022-03-03 22:15:26 +01:00
|
|
|
|
2022-04-20 14:01:00 +02:00
|
|
|
local keys = {
|
|
|
|
-- Navigation
|
|
|
|
["[c"] = { "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'", "Previous hunk/diff", expr = true },
|
|
|
|
["]c"] = { "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'", "Next hunk/diff", expr = true },
|
|
|
|
|
|
|
|
-- Commands
|
|
|
|
["<leader>g"] = {
|
|
|
|
name = "Git",
|
|
|
|
-- Actions
|
|
|
|
b = { gitsigns.toggle_current_line_blame, "Toggle blame virtual text" },
|
|
|
|
d = { gitsigns.diffthis, "Diff buffer" },
|
2023-05-06 19:58:30 +02:00
|
|
|
-- stylua: ignore
|
2022-04-20 14:01:00 +02:00
|
|
|
D = { function() gitsigns.diffthis("~") end, "Diff buffer against last commit" },
|
|
|
|
g = { "<cmd>Git<CR>", "Git status" },
|
|
|
|
h = { gitsigns.toggle_deleted, "Show deleted hunks" },
|
|
|
|
L = { "<cmd>:sp<CR><C-w>T:Gllog --follow -- %:p<CR>", "Current buffer log" },
|
|
|
|
m = { "<Plug>(git-messenger)", "Current line blame" },
|
|
|
|
p = { gitsigns.preview_hunk, "Preview hunk" },
|
|
|
|
r = { gitsigns.reset_hunk, "Restore hunk" },
|
|
|
|
R = { gitsigns.reset_buffer, "Restore buffer" },
|
|
|
|
s = { gitsigns.stage_hunk, "Stage hunk" },
|
|
|
|
S = { gitsigns.stage_buffer, "Stage buffer" },
|
|
|
|
u = { gitsigns.undo_stage_hunk, "Undo stage hunk" },
|
|
|
|
["["] = { gitsigns.prev_hunk, "Previous hunk" },
|
|
|
|
["]"] = { gitsigns.next_hunk, "Next hunk" },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local objects = {
|
|
|
|
["ih"] = { gitsigns.select_hunk, "Git hunk" },
|
|
|
|
}
|
|
|
|
|
|
|
|
local visual = {
|
|
|
|
["ih"] = { gitsigns.select_hunk, "Git hunk" },
|
|
|
|
|
|
|
|
-- Only the actual command can make use of the visual selection...
|
|
|
|
["<leader>g"] = {
|
|
|
|
name = "Git",
|
2024-07-12 20:52:03 +02:00
|
|
|
p = { gitsigns.preview_hunk, "Preview selection" },
|
|
|
|
r = { make_visual(gitsigns.reset_hunk), "Restore selection" },
|
|
|
|
s = { make_visual(gitsigns.stage_hunk), "Stage selection" },
|
|
|
|
u = { gitsigns.undo_stage_hunk, "Undo stage selection" },
|
2022-04-20 14:01:00 +02:00
|
|
|
},
|
|
|
|
}
|
2022-03-03 22:15:26 +01:00
|
|
|
|
2022-04-20 14:01:00 +02:00
|
|
|
wk.register(keys, { buffer = bufnr })
|
|
|
|
wk.register(objects, { buffer = bufnr, mode = "o" })
|
|
|
|
wk.register(visual, { buffer = bufnr, mode = "x" })
|