return {
  'lewis6991/gitsigns.nvim',
  dependencies = { 'nvim-lua/plenary.nvim' },
  event = 'VeryLazy',
  opts = {
    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 '<Ignore>'
      end, { expr = true, desc = 'Git next hunk' })

      map('n', '[c', function()
        if vim.wo.diff then return '[c' end
        vim.schedule(function() gs.prev_hunk() end)
        return '<Ignore>'
      end, { expr = true, desc = 'Git prev hunk' })

      -- Actions
      map({ 'n', 'v' }, '<leader>gs', ':Gitsigns stage_hunk<CR>', { desc = 'Gitsigns stage hunk' })
      map({ 'n', 'v' }, '<leader>gr', ':Gitsigns reset_hunk<CR>', { desc = 'Gitsigns reset hunk' })
      map('n', '<leader>gS', gs.stage_buffer, { desc = 'Gitsigns stage buffer' })
      map('n', '<leader>gu', gs.undo_stage_hunk, { desc = 'Gitsigns undo stage hunk' })
      map('n', '<leader>gR', gs.reset_buffer, { desc = 'Gitsigns reset buffer' })
      map('n', '<leader>gp', gs.preview_hunk, { desc = 'Gitsigns preview hunk' })
      map('n', '<leader>gb', function() gs.blame_line { full = true } end, { desc = 'Gitsigns blame line' })
      map('n', '<leader>gtb', gs.toggle_current_line_blame, { desc = 'Gitsigns toggle blame line' })
      map('n', '<leader>gtd', gs.toggle_deleted, { desc = 'Gitsigns toggle deleted' })
      map('n', '<leader>gd', gs.diffthis, { desc = 'Gitsigns diff this' })
      map('n', '<leader>gDD', function() gs.diffthis('~') end, { desc = 'Gitsigns diff this ~' })
      map('n', '<leader>gD', function()
        vim.ui.input({ prompt = 'Branch?' }, function(input)
          gs.diffthis(input)
        end)
      end, { desc = 'Gitsigns diff this' })

      -- Text object
      map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'Inner git hunk' })
    end,
  },
}
