Add gitsigns essential keymaps

Include essential gitsigns keymaps, for more see gitsigns README:
https://github.com/lewis6991/gitsigns.nvim
This commit is contained in:
Damjan 9000 2024-03-11 00:58:30 +01:00
parent 773e482d4b
commit 5a95462384

View File

@ -255,6 +255,33 @@ require('lazy').setup({
topdelete = { text = '' },
changedelete = { text = '~' },
},
on_attach = function(bufnr)
-- Include essential gitsigns keymaps, for more see gitsigns README:
-- https://github.com/lewis6991/gitsigns.nvim
local gs = package.loaded.gitsigns
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map({ 'n', 'v' }, ']c', gs.next_hunk, { desc = 'Jump to next git [c]hange' })
map({ 'n', 'v' }, '[c', gs.prev_hunk, { desc = 'Jump to previous git [c]hange' })
-- Actions
map('n', '<leader>hs', gs.stage_hunk, { desc = 'git [s]tage hunk' })
map('n', '<leader>hr', gs.reset_hunk, { desc = 'git [r]eset hunk' })
map('n', '<leader>hu', gs.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' })
map('n', '<leader>hp', gs.preview_hunk, { desc = 'git [p]review hunk' })
map('n', '<leader>hb', gs.blame_line, { desc = 'git [b]lame line' })
map('n', '<leader>hd', gs.diffthis, { desc = 'git [d]iff against index' })
-- Visual mode
map('v', '<leader>hs', function()
gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' }
end, { desc = 'stage git hunk' })
map('v', '<leader>hr', function()
gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' }
end, { desc = 'reset git hunk' })
end,
},
},
@ -286,7 +313,12 @@ require('lazy').setup({
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
}
-- visual mode
require('which-key').register({
['<leader>h'] = { 'Git [H]unk' },
}, { mode = 'v' })
end,
},