Compare commits
2 commits
530badbabd
...
a25b541650
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | a25b541650 | ||
Bruno BELANYI | 11201a685d |
|
@ -1,6 +1,29 @@
|
|||
local gitsigns = require("gitsigns")
|
||||
local wk = require("which-key")
|
||||
|
||||
--- 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
|
||||
|
||||
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({
|
||||
current_line_blame_opts = {
|
||||
-- Show the blame quickly
|
||||
|
@ -10,8 +33,8 @@ gitsigns.setup({
|
|||
|
||||
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 },
|
||||
["[c"] = { nav_hunk("prev"), "Previous hunk/diff" },
|
||||
["]c"] = { nav_hunk("next"), "Next hunk/diff" },
|
||||
|
||||
-- Commands
|
||||
["<leader>g"] = {
|
||||
|
@ -46,10 +69,10 @@ local visual = {
|
|||
-- Only the actual command can make use of the visual selection...
|
||||
["<leader>g"] = {
|
||||
name = "Git",
|
||||
p = { ":Gitsigns preview_hunk<CR>", "Preview selection" },
|
||||
r = { ":Gitsigns reset_hunk<CR>", "Restore selection" },
|
||||
s = { ":Gitsigns stage_hunk<CR>", "Stage selection" },
|
||||
u = { ":Gitsigns undo_stage_hunk<CR>", "Undo stage selection" },
|
||||
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" },
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue