require('gitsigns').setup { on_attach = function(bufnr) local gs = package.loaded.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', 'gn', function() if vim.wo.diff then return ']c' end vim.schedule(function() gs.next_hunk() end) return '' end, {expr=true}) map('n', 'gN', function() if vim.wo.diff then return '[c' end vim.schedule(function() gs.prev_hunk() end) return '' end, {expr=true}) map('n', 'gs', gs.stage_hunk) map('n', 'gr', gs.reset_hunk) map('n', 'gd', gs.diffthis) map('n', 'gd', function() gs.diffthis('~') end) end }