summaryrefslogtreecommitdiff
path: root/ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/harpoon2.lua
blob: c68f385ab85a1b24a79ebc50df0ed549703fa233 (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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
return {
	"ThePrimeagen/harpoon",
	branch = "harpoon2",
	opts = {
		menu = {
			width = vim.api.nvim_win_get_width(0) - 4,
		},
		settings = {
			save_on_toggle = true,
		},
	},
	init = function()
		local wk = require("which-key")
		wk.add({
			mode = { "n" },
			{ "<leader>h", group = "Harpoon" },
			{ "<leader>hr", group = "Replace harpoon slot" },
			{ "<M-x>", group = "Harpoon list delete" },
		})
	end,
	config = function(_, opts)
		local harpoon = require("harpoon")

		-- Apply the base configuration
		harpoon.setup(opts)

		-- Extend functionality
		harpoon:extend({
			UI_CREATE = function(cx)
				vim.keymap.set("n", "<C-v>", function()
					harpoon.ui:select_menu_item({ vsplit = true })
				end, { buffer = cx.bufnr })

				vim.keymap.set("n", "<C-s>", function()
					harpoon.ui:select_menu_item({ split = true })
				end, { buffer = cx.bufnr })

				vim.keymap.set("n", "<C-t>", function()
					harpoon.ui:select_menu_item({ tabedit = true })
				end, { buffer = cx.bufnr })
			end,
		})
	end,
	keys = function()
		local keys = {
			{
				"<leader>ha",
				function()
					require("harpoon"):list():add()
				end,
				desc = "Add buffer to harpoon list",
			},
			{
				"<leader>hi",
				function()
					require("harpoon"):list():prepend()
				end,
				desc = "Prepend buffer to harpoon list",
			},
			{
				"<C-q>",
				function()
					local harpoon = require("harpoon")
					harpoon.ui:toggle_quick_menu(harpoon:list())
				end,
				desc = "Open harpoon list menu",
			},
			{
				"<C-S-P>",
				function()
					require("harpoon"):list():prev({ ui_nav_wrap = false })
				end,
				desc = "Previous harpoon list",
			},
			{
				"<C-S-N>",
				function()
					require("harpoon"):list():next({ ui_nav_wrap = false })
				end,
				desc = "Next harpoon list",
			},
		}

		for i = 0, 9 do
			table.insert(keys, {
				"<M-" .. i .. ">",
				function()
					require("harpoon"):list():select(i)
				end,
				desc = "Harpoon list " .. i,
			})
			table.insert(keys, {
				"<leader>h" .. i,
				function()
					require("harpoon"):list():select(i)
				end,
				desc = "Harpoon list " .. i,
			})
			table.insert(keys, {
				"<leader>hr" .. i,
				function()
					require("harpoon"):list():replace_at(i)
				end,
				desc = "Replace buffer at harpoon slot " .. i,
			})
		end

		return keys
	end,
}