summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Angelopoulos <george@usermod.net>2023-08-22 07:17:15 +0300
committerGeorge Angelopoulos <george@usermod.net>2023-08-22 07:17:15 +0300
commit38a0f0323196c406e6e81d52052b2ac213bfe709 (patch)
treed88f9f659912faca59dc2d33c591ff93d19d8d5d
parent01a1ebed38c5ef28cfe1409f8589bce60b7b727b (diff)
Revert gitsigns keymaps but fix vimdiff and fugitive conflict
Originally, the keymaps for jumping to next and previous git hunks were ]c and [c. This was changed in #323 (83b65a1) because they overwrote the built-in vimdiff keymaps. However, the more traditional solution is to have ]c and [c *extend* the built-in keymap. This is what fugitive and gitgutter have been doing for years. Gitsigns doesn't do this by itself, but it has a recommended keymap configuration on which the present patch is based: https://github.com/lewis6991/gitsigns.nvim#keymaps The only thing I've added is to have the keymaps work in visual mode as well, which is the same behavior as the built in vimdiff keymaps.
-rw-r--r--init.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/init.lua b/init.lua
index 1332c3b..8c21366 100644
--- a/init.lua
+++ b/init.lua
@@ -124,9 +124,20 @@ require('lazy').setup({
changedelete = { text = '~' },
},
on_attach = function(bufnr)
- vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' })
- vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' })
- vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' })
+ vim.keymap.set('n', '<leader>hp', require('gitsigns').preview_hunk, { buffer = bufnr, desc = 'Preview git hunk' })
+
+ -- don't override the built-in and fugitive keymaps
+ local gs = package.loaded.gitsigns
+ vim.keymap.set({'n', 'v'}, ']c', function()
+ if vim.wo.diff then return ']c' end
+ vim.schedule(function() gs.next_hunk() end)
+ return '<Ignore>'
+ end, {expr=true, buffer = bufnr, desc = "Jump to next hunk"})
+ vim.keymap.set({'n', 'v'}, '[c', function()
+ if vim.wo.diff then return '[c' end
+ vim.schedule(function() gs.prev_hunk() end)
+ return '<Ignore>'
+ end, {expr=true, buffer = bufnr, desc = "Jump to previous hunk"})
end,
},
},