2024-02-26 19:46:46 +00:00
|
|
|
-- Here is a more advanced example where we pass configuration
|
2024-03-18 17:50:47 +00:00
|
|
|
-- options to `gitsigns.nvim`. This is equivalent to the following Lua:
|
2024-02-26 19:46:46 +00:00
|
|
|
-- require('gitsigns').setup({ ... })
|
|
|
|
--
|
|
|
|
-- See `:help gitsigns` to understand what the configuration keys do
|
|
|
|
return {
|
|
|
|
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
|
|
|
|
'lewis6991/gitsigns.nvim',
|
|
|
|
opts = {
|
|
|
|
signs = {
|
|
|
|
add = { text = '+' },
|
|
|
|
change = { text = '~' },
|
|
|
|
delete = { text = '_' },
|
|
|
|
topdelete = { text = '‾' },
|
|
|
|
changedelete = { text = '~' },
|
2024-04-05 07:11:57 +00:00
|
|
|
},
|
|
|
|
on_attach = function(bufnr)
|
2024-04-18 01:00:39 +00:00
|
|
|
local gitsigns = require 'gitsigns'
|
2024-03-01 08:15:22 +00:00
|
|
|
|
|
|
|
local function map(mode, l, r, opts)
|
|
|
|
opts = opts or {}
|
|
|
|
opts.buffer = bufnr
|
|
|
|
vim.keymap.set(mode, l, r, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Navigation
|
2024-04-18 01:00:39 +00:00
|
|
|
map('n', ']c', function()
|
2024-03-01 08:15:22 +00:00
|
|
|
if vim.wo.diff then
|
2024-04-18 01:00:39 +00:00
|
|
|
vim.cmd.normal { ']c', bang = true }
|
|
|
|
else
|
|
|
|
gitsigns.nav_hunk 'next'
|
2024-03-01 08:15:22 +00:00
|
|
|
end
|
2024-04-18 01:00:39 +00:00
|
|
|
end, { desc = 'Jump to next git [c]hange' })
|
2024-03-01 08:15:22 +00:00
|
|
|
|
2024-04-18 01:00:39 +00:00
|
|
|
map('n', '[c', function()
|
2024-03-01 08:15:22 +00:00
|
|
|
if vim.wo.diff then
|
2024-04-18 01:00:39 +00:00
|
|
|
vim.cmd.normal { '[c', bang = true }
|
|
|
|
else
|
|
|
|
gitsigns.nav_hunk 'prev'
|
2024-03-01 08:15:22 +00:00
|
|
|
end
|
2024-04-18 01:00:39 +00:00
|
|
|
end, { desc = 'Jump to previous git [c]hange' })
|
2024-03-01 08:15:22 +00:00
|
|
|
|
|
|
|
-- Actions
|
|
|
|
-- visual mode
|
|
|
|
map('v', '<leader>hs', function()
|
2024-04-18 01:00:39 +00:00
|
|
|
gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' }
|
2024-03-01 08:15:22 +00:00
|
|
|
end, { desc = 'stage git hunk' })
|
|
|
|
map('v', '<leader>hr', function()
|
2024-04-18 01:00:39 +00:00
|
|
|
gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' }
|
2024-03-01 08:15:22 +00:00
|
|
|
end, { desc = 'reset git hunk' })
|
|
|
|
-- normal mode
|
2024-04-18 01:00:39 +00:00
|
|
|
map('n', '<leader>hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' })
|
|
|
|
map('n', '<leader>hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' })
|
|
|
|
map('n', '<leader>hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' })
|
|
|
|
map('n', '<leader>hu', gitsigns.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' })
|
|
|
|
map('n', '<leader>hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' })
|
|
|
|
map('n', '<leader>hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' })
|
|
|
|
map('n', '<leader>hb', gitsigns.blame_line, { desc = 'git [b]lame line' })
|
|
|
|
map('n', '<leader>hd', gitsigns.diffthis, { desc = 'git [d]iff against index' })
|
2024-03-01 08:15:22 +00:00
|
|
|
map('n', '<leader>hD', function()
|
2024-04-18 01:00:39 +00:00
|
|
|
gitsigns.diffthis '@'
|
|
|
|
end, { desc = 'git [D]iff against last commit' })
|
2024-03-01 08:15:22 +00:00
|
|
|
-- Toggles
|
2024-04-18 01:00:39 +00:00
|
|
|
map('n', '<leader>tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' })
|
|
|
|
map('n', '<leader>tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' })
|
2024-03-01 08:15:22 +00:00
|
|
|
|
|
|
|
-- Text object
|
|
|
|
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'select git hunk' })
|
|
|
|
end,
|
2024-02-26 19:46:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
-- vim: ts=2 sts=2 sw=2 et
|