summaryrefslogtreecommitdiff
path: root/config/nvim/lua/plugins/git.lua
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-09-17 19:45:23 +0100
committerIgor Soarez <igor@soarez.org>2026-09-17 19:45:23 +0100
commit13cc065ec014b86369dfe4ad60d1a43fa06fd251 (patch)
tree684690c61b7b59758c2aac132c65b81c86de0608 /config/nvim/lua/plugins/git.lua
dotfiles
Shell, editor and terminal configuration, the tools that go with them, and szecret, an age-based secret manager whose store lives elsewhere. History restarts here. What came before was not written to be read by anyone else, and carried machine names, addresses and an encrypted secret store; it is kept privately instead. What is left is meant to be safe on any machine, including one whose owner is not me: see CLAUDE.md for the rule it is written to.
Diffstat (limited to 'config/nvim/lua/plugins/git.lua')
-rw-r--r--config/nvim/lua/plugins/git.lua63
1 files changed, 63 insertions, 0 deletions
diff --git a/config/nvim/lua/plugins/git.lua b/config/nvim/lua/plugins/git.lua
new file mode 100644
index 0000000..ad120f4
--- /dev/null
+++ b/config/nvim/lua/plugins/git.lua
@@ -0,0 +1,63 @@
+return {
+ {
+ "lewis6991/gitsigns.nvim",
+ config = function()
+ -- Git hunk navigation
+ local gs = require("gitsigns")
+ gs.setup({
+ signs_staged_enable = true,
+ signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
+ numhl = true, -- Toggle with `:Gitsigns toggle_numhl`
+ linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
+ word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
+ current_line_blame_opts = {
+ virt_text_pos = 'right_align', -- 'eol' | 'overlay' | 'right_align'
+ },
+ -- current_line_blame = true,
+ -- current_line_blame_formatter = '<author>, <author_time:%R> - <summary>',
+ })
+ vim.keymap.set("n", "[g", gs.prev_hunk, { desc = "Goto previous git hunk" })
+ vim.keymap.set("n", "]g", gs.next_hunk, { desc = "Goto next git hunk" })
+
+ -- vim.keymap.set("n", "<Leader>cg", gitsigns.preview_hunk, { desc = "Preview git hunk" })
+ vim.keymap.set("n", "<Leader>gd", function() gs.preview_hunk_inline() end, { desc = "Preview hunk inline" })
+ vim.keymap.set("n", "<Leader>gD", function() gs.preview_hunk() end, { desc = "Preview hunk popup" })
+ vim.keymap.set("n", "<Leader>gf", function() gs.diffthis() end, { desc = "Diff file" })
+ vim.keymap.set("n", "<Leader>gr", function() gs.reset_hunk() end, { desc = "Revert hunk" })
+ vim.keymap.set("n", "<Leader>gs", function() gs.stage_hunk() end, { desc = "Stage hunk" })
+ vim.keymap.set("n", "<Leader>ga", function() gs.stage_buffer() end, { desc = "Stage buffer" })
+ vim.keymap.set("n", "<Leader>gB", function() gs.toggle_current_line_blame() end, { desc = "Toggle current line blame (virtual text)" })
+ vim.keymap.set("n", "<Leader>gb", function() gs.blame() end, { desc = "Open blame" })
+
+ -- Select hunks as a text object.
+ vim.keymap.set({'o', 'x'}, 'ih', '<Cmd>Gitsigns select_hunk<CR>')
+
+ -- Open current file/line (or visual selection) on the git remote
+ vim.keymap.set({ "n", "x" }, "<Leader>go", function() Snacks.gitbrowse() end, { desc = "Open in remote (browser)" })
+ end,
+ },
+ -- Lazy-loaded: kept only for its `:Git <arbitrary>` escape hatch and :Gblame,
+ -- since neogit + diffview + gitsigns cover day-to-day staging/diff/blame.
+ {
+ "tpope/vim-fugitive",
+ cmd = { "Git", "G", "Gdiffsplit", "Gread", "Gwrite", "Gedit", "Gblame", "Gclog" },
+ },
+ {
+ "NeogitOrg/neogit",
+ lazy = true,
+ dependencies = {
+ "nvim-lua/plenary.nvim", -- required
+ "sindrets/diffview.nvim", -- optional - Diff integration
+
+ -- Only one of these is needed.
+ "ibhagwan/fzf-lua", -- optional
+ -- "nvim-telescope/telescope.nvim", -- optional
+ -- "nvim-mini/mini.pick", -- optional
+ -- "folke/snacks.nvim", -- optional
+ },
+ cmd = "Neogit",
+ keys = {
+ { "<leader>gg", "<cmd>Neogit<cr>", desc = "Show Neogit UI" }
+ }
+ },
+}