update harpoon to harpoon 2

This commit is contained in:
2024-03-09 00:02:02 -05:00
parent 6deb1b6a6b
commit debeca659a
4 changed files with 76 additions and 9 deletions

6
after/plugin/harpoon.lua Normal file
View File

@ -0,0 +1,6 @@
local status_ok, harpoon = pcall(require, "harpoon")
if not status_ok then
return
end
harpoon.setup {}

View File

@ -104,21 +104,24 @@ if pcall(require, "telescope") then
end
-- harpoon
if pcall(require, 'harpoon') then
local mark = require("harpoon.mark")
local ui = require("harpoon.ui")
if (pcall(require, 'harpoon')) then
local harpoon = require("harpoon")
map("n", "<leader>a", function()
mark.add_file()
harpoon:list():append()
vim.notify('added new file to quickmarks', vim.log.levels.INFO, {
title = misc.appid,
})
end)
map("n", "<C-e>", ui.toggle_quick_menu)
map('n', '<C-q>', function() ui.nav_file(1) end)
map('n', '<C-g>', function() ui.nav_file(2) end)
map('n', '<C-h>', function() ui.nav_file(3) end)
map('n', '<C-i>', function() ui.nav_file(4) end)
map('n', '<C-q>', function() harpoon:list():select(1) end)
map('n', '<C-g>', function() harpoon:list():select(2) end)
map('n', '<C-h>', function() harpoon:list():select(3) end)
map('n', '<C-i>', function() harpoon:list():select(4) end)
map("n", "<C-S-P>", function() harpoon:list():prev() end)
map("n", "<C-S-N>", function() harpoon:list():next() end)
map("n", "<C-e>", function() require("core.harpoon").switcher() end)
end
map('n', '<leader>u', '<cmd>UndotreeToggle<CR>', { desc = 'Open undo tree.' })

View File

@ -43,6 +43,7 @@ require('dep') {
{ 'ahmedkhalf/project.nvim' }, -- cd into root of project
{ 'mrjones2014/smart-splits.nvim'}, -- buffer resizing
{ 'ThePrimeagen/harpoon', -- super duper fast navigation through files
branch = 'harpoon2',
requires = 'nvim-lua/plenary.nvim'
},

57
lua/core/harpoon.lua Normal file
View File

@ -0,0 +1,57 @@
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_set = require("telescope.actions.set")
local action_state = require("telescope.actions.state")
local harpoon = require('harpoon')
local M = {}
function M.switcher()
local filepaths = {}
for _, item in ipairs(harpoon:list().items) do
table.insert(filepaths, item.value)
end
pickers.new({
prompt_title = "Harpoon",
finder = finders.new_table { results = filepaths },
sorter = conf.generic_sorter(),
previewer = conf.file_previewer {},
attach_mappings = function(prompt_bufnr, map)
actions.move_selection_previous:replace(function()
action_set.shift_selection(prompt_bufnr, -1)
end)
actions.move_selection_next:replace(function()
action_set.shift_selection(prompt_bufnr, 1)
end)
-- remove harpoon item
-- TODO:
-- select items, and open buffer
vim.keymap.set("n", "<C-v>", function()
if action_state.get_selected_entry() then
actions.close(prompt_bufnr)
vim.cmd("vsplit "..action_state.get_selected_entry()[1])
end
end)
vim.keymap.set({ "n", "i" }, "<C-s>", function()
if action_state.get_selected_entry() then
actions.close(prompt_bufnr)
vim.cmd("split "..action_state.get_selected_entry()[1])
end
end)
actions.select_default:replace(function()
if action_state.get_selected_entry() then
actions.close(prompt_bufnr)
vim.cmd("e "..action_state.get_selected_entry()[1])
end
end)
return true
end
}):find()
end
return M