Skip to content

Commit

Permalink
feat(nvim): gitsigns alternative bind next/prev hunk (M-n/M-p)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagy135 committed Jun 10, 2022
1 parent 97e5911 commit 6db759d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nvim/.config/nvim/lua/binds/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ M.set = function(gs, bufnr)
vim.keymap.set(mode, l, r, opts)
end

-- Navigation
map('n', ']h', function()
local next_hunk = function ()
if vim.wo.diff then return ']h' end
vim.schedule(function() gs.next_hunk() end)
return '<Ignore>'
end, { expr = true })
end

map('n', '[h', function()
local prev_hunk = function ()
if vim.wo.diff then return '[h' end
vim.schedule(function() gs.prev_hunk() end)
return '<Ignore>'
end, { expr = true })
end

-- Navigation
map('n', ']h', next_hunk, { expr = true })
map('n', '<M-n>', next_hunk, { expr = true })

map('n', '[h', prev_hunk, { expr = true })
map('n', '<M-p>', prev_hunk, { expr = true })

-- Actions
map({ 'n', 'v' }, '<leader>hs', ':Gitsigns stage_hunk<CR>', { desc = 'Stage hunk' })
Expand Down

0 comments on commit 6db759d

Please sign in to comment.