From 5a954623844f333d515227306ffb5af54b44ae25 Mon Sep 17 00:00:00 2001 From: Damjan 9000 Date: Mon, 11 Mar 2024 00:58:30 +0100 Subject: [PATCH] Add gitsigns essential keymaps Include essential gitsigns keymaps, for more see gitsigns README: https://github.com/lewis6991/gitsigns.nvim --- init.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/init.lua b/init.lua index 013fcc2..a58715c 100644 --- a/init.lua +++ b/init.lua @@ -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', 'hs', gs.stage_hunk, { desc = 'git [s]tage hunk' }) + map('n', 'hr', gs.reset_hunk, { desc = 'git [r]eset hunk' }) + map('n', 'hu', gs.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' }) + map('n', 'hp', gs.preview_hunk, { desc = 'git [p]review hunk' }) + map('n', 'hb', gs.blame_line, { desc = 'git [b]lame line' }) + map('n', 'hd', gs.diffthis, { desc = 'git [d]iff against index' }) + -- Visual mode + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'stage git hunk' }) + map('v', '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({ ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, } + -- visual mode + require('which-key').register({ + ['h'] = { 'Git [H]unk' }, + }, { mode = 'v' }) end, },