1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
-- Adapted from the original init.vim; mappings are buffer-local.
local gs = require('gitsigns')
gs.setup({
on_attach = function(bufnr)
local function map(mode, lhs, rhs)
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true })
end
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
map('n', ']h', function()
if vim.wo.diff then vim.cmd.normal({ ']c', bang = true })
else gs.nav_hunk('next') end
end)
map('n', '[h', function()
if vim.wo.diff then vim.cmd.normal({ '[c', bang = true })
else gs.nav_hunk('prev') end
end)
map('n', '<leader>hs', gs.stage_hunk)
map('n', '<leader>hr', gs.reset_hunk)
map('v', '<leader>hs', function() gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end)
map('v', '<leader>hr', function() gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end)
map('n', '<leader>hS', gs.stage_buffer)
map('n', '<leader>hR', gs.reset_buffer)
map('n', '<leader>hp', gs.preview_hunk)
map('n', '<leader>hi', gs.preview_hunk_inline)
end,
})
|