return { 'ThePrimeagen/harpoon', branch = 'harpoon2', dependencies = { 'nvim-lua/plenary.nvim', 'nvim-telescope/telescope.nvim' }, config = function() local harpoon = require 'harpoon' harpoon:setup { settings = { save_on_toggle = true, sync_on_ui_close = true } } -- Harpoon list in a Telescope picker, removes the selected mark. 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', '', delete_mark) map('n', '', delete_mark) return true end, }) :find() end local map = vim.keymap.set map('n', 'a', function() harpoon:list():add() end, { desc = 'Harpoon: [A]dd file' }) map('n', 'A', function() harpoon:list():remove() end, { desc = 'Harpoon: remove current file' }) map('n', '', function() toggle_telescope(harpoon:list()) end, { desc = 'Harpoon: quick menu' }) -- 1..4 instead of Prime's : those collide with window navigation and -- with (jump back after gd) unless you are on a Dvorak home row. for i = 1, 4 do map('n', '' .. i, function() harpoon:list():select(i) end, { desc = 'Harpoon: file ' .. i }) end -- / never worked: terminals can't tell Ctrl+Shift+p from Ctrl+p. map('n', '[h', function() harpoon:list():prev() end, { desc = 'Harpoon: previous mark' }) map('n', ']h', function() harpoon:list():next() end, { desc = 'Harpoon: next mark' }) end, }