-- 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', ':Gitsigns select_hunk') 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', 'hs', gs.stage_hunk) map('n', 'hr', gs.reset_hunk) map('v', 'hs', function() gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end) map('v', 'hr', function() gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end) map('n', 'hS', gs.stage_buffer) map('n', 'hR', gs.reset_buffer) map('n', 'hp', gs.preview_hunk) map('n', 'hi', gs.preview_hunk_inline) end, })