require('gitsigns').setup({ update_debounce = 500, 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', ']c', function() if vim.wo.diff then return ']c' end vim.schedule(function() gs.next_hunk() end) return '' end, { expr = true, desc = "Jump to next git hunk [C]hange" }) map('n', '[c', function() if vim.wo.diff then return '[c' end vim.schedule(function() gs.prev_hunk() end) return '' end, { expr = true, desc = "Jump to previous git hunk [C]hange" }) -- Actions map({ 'n', 'v' }, 'hs', ':Gitsigns stage_hunk', { desc = "[S]tage git [H]unk" }) map({ 'n', 'v' }, 'hr', ':Gitsigns reset_hunk', { desc = "[R]eset git [H]unk" }) map('n', 'hS', gs.stage_buffer, { desc = "[S]tage git buffer" }) map('n', 'hu', gs.undo_stage_hunk, { desc = "[U]ndo git [H]unk" }) map('n', 'hR', gs.reset_buffer, { desc = "[R]eset git buffer" }) map('n', 'hp', gs.preview_hunk, { desc = "[P]review git [H]unk" }) map('n', 'hb', function() gs.blame_line { full = true } end, { desc = "Git [B]lame line" }) map('n', 'tb', gs.toggle_current_line_blame, { desc = "[T]oggle current line git [B]lame" }) map('n', 'hd', gs.diffthis, { desc = "Git [D]iff current file with index" }) map('n', 'hD', function() gs.diffthis('~') end, { desc = "Git [D]iff current file with last commit" }) map('n', 'td', gs.toggle_deleted, { desc = "[T]oggle showing [D]eleted git hunks" }) -- Text object map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = "Select git [H]unk under cursor" }) end })