all repos — dot @ 13cc065ec014b86369dfe4ad60d1a43fa06fd251

Shell, editor and terminal configuration, and the tools that go with them

config/nvim/lua/plugins/git.lua (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 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" }
		}
	},
}