diff --git a/lazy-lock.json b/lazy-lock.json index 5f58475..343633e 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -3,6 +3,7 @@ "fidget.nvim": { "branch": "main", "commit": "7fa433a83118a70fe24c1ce88d5f0bd3453c0970" }, "friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" }, "fzf-lua": { "branch": "main", "commit": "bde73a6886b607246095aa59f396de5e0d036890" }, + "gitsigns.nvim": { "branch": "main", "commit": "0d797daee85366bc242580e352a4f62d67557b84" }, "gruvbox.nvim": { "branch": "main", "commit": "334d5fd49fc8033f26408425366c66c6390c57bb" }, "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, "lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" }, diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..ada564e --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,64 @@ +return { + 'lewis6991/gitsigns.nvim', + event = 'BufReadPre', + + ---@module 'gitsigns' + ---@type GitSigns.Config + opts = { + signs = { + add = { text = '┃' }, + change = { text = '┃' }, + delete = { text = '▁' }, + topdelete = { text = '▔' }, + changedelete = { text = '~' }, + untracked = { text = '┆' }, + }, + signs_staged = { + add = { text = '┃' }, + change = { text = '┃' }, + delete = { text = '▁' }, + topdelete = { text = '▔' }, + changedelete = { text = '~' }, + }, + signs_staged_enable = true, + current_line_blame = false, + + on_attach = function(bufnr) + local gs = require('gitsigns') + local function map(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc }) + end + + map('n', ']h', function() + if vim.wo.diff then + vim.cmd.normal({ ']c', bang = true }) + else + gs.nav_hunk('next') + end + end, 'Next hunk') + + map('n', '[h', function() + if vim.wo.diff then + vim.cmd.normal({ '[c', bang = true }) + else + gs.nav_hunk('prev') + end + end, 'Prev hunk') + + map('n', 'hs', function() + gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, 'Stage hunk (selection)') + + map('v', 'hr', function() + gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, 'Reset hunk (selection)') + + map('n', 'hp', gs.preview_hunk, 'Preview hunk') + map('n', 'hd', gs.diffthis, 'Diff this') + map('n', 'hD', function() gs.diffthis('~') end, 'Diff this (last commit)') + + map('n', 'gb', gs.toggle_current_line_blame, 'Toggle line blame') + map('n', 'gB', gs.blame, 'Blame buffer') + end + }, +}