Compare commits

..

2 commits

Author SHA1 Message Date
Bruno BELANYI a25b541650 home: vim: git: use lua in hunk mappings
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-07-12 20:12:57 +01:00
Bruno BELANYI 11201a685d home: vim: git: use lua in visual mappings
I thought the partial staging feature had broken, but it looks to be
unrelated [1].

[1]: https://github.com/lewis6991/gitsigns.nvim/issues/1088
2024-07-12 20:12:57 +01:00

View file

@ -10,6 +10,20 @@ local function make_visual(f)
end end
end end
local function nav_hunk(dir)
return function()
if vim.wo.diff then
local map = {
prev = "[c",
next = "]c",
}
vim.cmd.normal({ map[dir], bang = true })
else
gitsigns.nav_hunk(dir)
end
end
end
gitsigns.setup({ gitsigns.setup({
current_line_blame_opts = { current_line_blame_opts = {
-- Show the blame quickly -- Show the blame quickly
@ -19,8 +33,8 @@ gitsigns.setup({
local keys = { local keys = {
-- Navigation -- Navigation
["[c"] = { "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'", "Previous hunk/diff", expr = true }, ["[c"] = { nav_hunk("prev"), "Previous hunk/diff" },
["]c"] = { "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'", "Next hunk/diff", expr = true }, ["]c"] = { nav_hunk("next"), "Next hunk/diff" },
-- Commands -- Commands
["<leader>g"] = { ["<leader>g"] = {
@ -58,7 +72,7 @@ local visual = {
p = { gitsigns.preview_hunk, "Preview selection" }, p = { gitsigns.preview_hunk, "Preview selection" },
r = { make_visual(gitsigns.reset_hunk), "Restore selection" }, r = { make_visual(gitsigns.reset_hunk), "Restore selection" },
s = { make_visual(gitsigns.stage_hunk), "Stage selection" }, s = { make_visual(gitsigns.stage_hunk), "Stage selection" },
u = { gitsigns.undo_stage_hunk, "Undo stage hunk" }, u = { gitsigns.undo_stage_hunk, "Undo stage selection" },
}, },
} }