diff options
author | Damjan 9000 <damjan.9000@gmail.com> | 2024-04-18 11:06:10 +0200 |
---|---|---|
committer | Damjan 9000 <damjan.9000@gmail.com> | 2024-04-18 11:11:37 +0200 |
commit | 517da30837576f3aac31e343c715ea069e6feef2 (patch) | |
tree | 4bab719ffc996c664a109acc052100a8f3c05205 | |
parent | 3d2daa7965e931b75679e435e91a49424d5168c2 (diff) | |
parent | f5c9fe8e15aafb6857706e3c05b5eee4ecb98a2b (diff) |
Merge 'upstream' Add gitsigns recommended keymaps
Note, the upstream base gitsigns config and optional gitsigns plugin are merged
into the same plugin spec, so the gitsigns keymaps are enabled by default.
-rw-r--r-- | lua/kickstart/plugins/gitsigns.lua | 50 | ||||
-rw-r--r-- | lua/kickstart/plugins/which-key.lua | 5 |
2 files changed, 55 insertions, 0 deletions
diff --git a/lua/kickstart/plugins/gitsigns.lua b/lua/kickstart/plugins/gitsigns.lua index 24bd14b..b8918ce 100644 --- a/lua/kickstart/plugins/gitsigns.lua +++ b/lua/kickstart/plugins/gitsigns.lua @@ -14,6 +14,56 @@ return { topdelete = { text = '‾' }, changedelete = { text = '~' }, }, + on_attach = function(bufnr) + local gitsigns = require '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', ']c', function() + if vim.wo.diff then + vim.cmd.normal { ']c', bang = true } + else + gitsigns.nav_hunk 'next' + end + end, { desc = 'Jump to next git [c]hange' }) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal { '[c', bang = true } + else + gitsigns.nav_hunk 'prev' + end + end, { desc = 'Jump to previous git [c]hange' }) + + -- Actions + -- visual mode + map('v', '<leader>hs', function() + gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'stage git hunk' }) + map('v', '<leader>hr', function() + gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'reset git hunk' }) + -- normal mode + map('n', '<leader>hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) + map('n', '<leader>hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) + map('n', '<leader>hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) + map('n', '<leader>hu', gitsigns.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' }) + map('n', '<leader>hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) + map('n', '<leader>hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) + map('n', '<leader>hb', gitsigns.blame_line, { desc = 'git [b]lame line' }) + map('n', '<leader>hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) + map('n', '<leader>hD', function() + gitsigns.diffthis '@' + end, { desc = 'git [D]iff against last commit' }) + -- Toggles + map('n', '<leader>tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) + map('n', '<leader>tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) + end, }, }, } diff --git a/lua/kickstart/plugins/which-key.lua b/lua/kickstart/plugins/which-key.lua index d37883b..54d7409 100644 --- a/lua/kickstart/plugins/which-key.lua +++ b/lua/kickstart/plugins/which-key.lua @@ -28,7 +28,12 @@ return { ['<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, }, } |