dotfiles/neovim/config/plugins/gitsigns.lua
Jonny Barnes 509b16f543
Add gitsigns via vim.pack, track the pack lockfile
Restores plugin management after the v0.12 config rewrite dropped the
earlier `vim.pack.add` calls. Plugins now live in `config/plugins/`,
one file per plugin, so adding the next is a single require.

Sets `<leader>` to Space for the gitsigns hunk mappings, and pins
'signcolumn' open so git and diagnostic signs don't shift text.

The lockfile moves into the repo and is symlinked by bootstrap.sh, as
the vim.pack docs recommend, giving reproducible plugin revisions
across machines and a rollback path via git. vim.pack writes it with a
truncating open, so it follows the symlink rather than replacing it.

Drops the orphaned nvim-tree entry, unreferenced since the rewrite.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 13:57:02 +01:00

55 lines
1.7 KiB
Lua

vim.pack.add({ 'https://github.com/lewis6991/gitsigns.nvim' })
require('gitsigns').setup({
on_attach = function(bufnr)
local gitsigns = require('gitsigns')
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc })
end
-- Navigation, falling back to vim's own diff motions in diff mode
map('n', ']c', function()
if vim.wo.diff then
vim.cmd.normal({ ']c', bang = true })
else
gitsigns.nav_hunk('next')
end
end, 'Next git hunk')
map('n', '[c', function()
if vim.wo.diff then
vim.cmd.normal({ '[c', bang = true })
else
gitsigns.nav_hunk('prev')
end
end, 'Previous git hunk')
-- Actions
map('n', '<leader>hs', gitsigns.stage_hunk, 'Stage hunk')
map('n', '<leader>hr', gitsigns.reset_hunk, 'Reset hunk')
map('v', '<leader>hs', function()
gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end, 'Stage selected hunk')
map('v', '<leader>hr', function()
gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end, 'Reset selected hunk')
map('n', '<leader>hS', gitsigns.stage_buffer, 'Stage buffer')
map('n', '<leader>hR', gitsigns.reset_buffer, 'Reset buffer')
map('n', '<leader>hp', gitsigns.preview_hunk, 'Preview hunk')
map('n', '<leader>hd', gitsigns.diffthis, 'Diff against index')
map('n', '<leader>hb', function()
gitsigns.blame_line({ full = true })
end, 'Blame line')
map('n', '<leader>hq', gitsigns.setqflist, 'Hunks to quickfix')
-- Toggles
map('n', '<leader>tb', gitsigns.toggle_current_line_blame, 'Toggle line blame')
map('n', '<leader>td', gitsigns.toggle_deleted, 'Toggle deleted lines')
end,
})