Skip to content

Commit

Permalink
Add gitsigns essential keymaps
Browse files Browse the repository at this point in the history
Include essential gitsigns keymaps, for more see gitsigns README:
https://github.com/lewis6991/gitsigns.nvim
  • Loading branch information
dam9000 committed Apr 17, 2024
1 parent 5540527 commit a57a176
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},

Expand Down Expand Up @@ -287,7 +314,12 @@ require('lazy').setup({
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
['<leader>t'] = { name = '[T]oggle', _ = '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,
},

Expand Down

0 comments on commit a57a176

Please sign in to comment.