Files
2026-10-08 10:09:21 -04:00

59 lines
2.4 KiB
Lua

return {
'ThePrimeagen/harpoon',
branch = 'harpoon2',
dependencies = { 'nvim-lua/plenary.nvim', 'nvim-telescope/telescope.nvim' },
config = function()
local harpoon = require 'harpoon'
harpoon:setup()
local conf = require('telescope.config').values
local function toggle_telescope(harpoon_files)
local file_paths = {}
local index_map = {}
for i = 1, harpoon_files:length() do
local item = harpoon_files:get(i)
if item then
table.insert(file_paths, item.value)
table.insert(index_map, i)
end
end
require('telescope.pickers')
.new({}, {
prompt_title = 'Harpoon',
finder = require('telescope.finders').new_table {
results = file_paths,
},
previewer = conf.file_previewer {},
sorter = conf.generic_sorter {},
attach_mappings = function(prompt_bufnr, map)
local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state'
local function delete_mark()
local selection = action_state.get_selected_entry()
harpoon:list():remove_at(index_map[selection.index])
actions.close(prompt_bufnr)
toggle_telescope(harpoon:list())
end
map('i', '<C-d>', delete_mark)
map('n', '<C-d>', delete_mark)
return true
end,
})
:find()
end
vim.keymap.set('n', '<leader>a', function() harpoon:list():add() end, { desc = 'Harpoon Add File' })
vim.keymap.set('n', '<leader>rm', function() harpoon:list():remove() end, { desc = 'Harpoon Remove Current File' })
vim.keymap.set('n', '<C-e>', function() toggle_telescope(harpoon:list()) end, { desc = 'Harpoon Quick Menu (Telescope)' })
vim.keymap.set('n', '<C-h>', function() harpoon:list():select(1) end, { desc = 'Harpoon to File 1' })
vim.keymap.set('n', '<C-t>', function() harpoon:list():select(2) end, { desc = 'Harpoon to File 2' })
vim.keymap.set('n', '<C-n>', function() harpoon:list():select(3) end, { desc = 'Harpoon to File 3' })
vim.keymap.set('n', '<C-s>', function() harpoon:list():select(4) end, { desc = 'Harpoon to File 4' })
vim.keymap.set('n', '<C-S-P>', function() harpoon:list():prev() end, { desc = 'Harpoon Prev' })
vim.keymap.set('n', '<C-S-N>', function() harpoon:list():next() end, { desc = 'Harpoon Next' })
end,
}