summaryrefslogtreecommitdiff
path: root/lua/ben/plugins/fugitive.lua
blob: 28edb7f494f6f73e3e0ceb6836c1f5e87656021b (plain)
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
return {
	"tpope/vim-fugitive",
	dependencies = "tpope/vim-rhubarb",
	-- Only enable on systems with git installed
	cond = function()
		return vim.fn.executable("git") == 1
	end,
	-- Only load when using one of the following commands:
	keys = {
		{ "<leader>gs", "<cmd>G<CR>" }, -- G.it S.tatus
		{ "<leader>gd", "<cmd>G difftool<CR>" }, -- G.it D.iff
		{ "<leader>gm", "<cmd>Gvdiffsplit!<CR>" }, -- G.it M.erge
		{ "<leader>gc", "<cmd>G commit<CR>" }, -- G.it C.ommit
		{ "<leader>gu", "<cmd>G push<CR>" }, -- G.it push U.pstream
		{ "<leader>gp", "<cmd>G pull<CR>" }, -- G.it P.ull
	},
	config = function()
		-- Use > and < to fix merge conflicts (keep the cursor in the middle of the screen)
		vim.api.nvim_set_keymap("n", ">", "<cmd>diffg //2<cr><cmd>diffupdate<cr>", { noremap = true, silent = true })
		vim.api.nvim_set_keymap("n", "<", "<cmd>diffg //3<cr><cmd>diffupdate<cr>", { noremap = true, silent = true })
		-- Use } and { to force the entire file
		vim.api.nvim_set_keymap(
			"n",
			"}",
			"<C-w>h<cmd>Gwrite!<cr><cmd>diffupdate<cr>",
			{ noremap = true, silent = true }
		)
		vim.api.nvim_set_keymap(
			"n",
			"{",
			"<C-w>l<cmd>Gwrite!<cr><cmd>diffupdate<cr>",
			{ noremap = true, silent = true }
		)
	end,
}