From e84927ba575fe7dd6666b3a06f0b1b4928795452 Mon Sep 17 00:00:00 2001 From: htom Date: Tue, 23 Sep 2025 14:59:02 +0200 Subject: [PATCH] working harpoon2 with telescope, keymap todo --- lua/custom/plugins/harpoon.lua | 64 ++++++++++++++++++++++++++++++++++ lua/custom/plugins/init.lua | 5 --- lua/custom/plugins/t | 20 +++++++++++ lua/lazy-plugins.lua | 2 +- 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 lua/custom/plugins/harpoon.lua delete mode 100644 lua/custom/plugins/init.lua create mode 100644 lua/custom/plugins/t diff --git a/lua/custom/plugins/harpoon.lua b/lua/custom/plugins/harpoon.lua new file mode 100644 index 0000000..6fd65f9 --- /dev/null +++ b/lua/custom/plugins/harpoon.lua @@ -0,0 +1,64 @@ +return { + 'ThePrimeagen/harpoon', + branch = 'harpoon2', + dependecies = { 'nvim-lua/plenary.nvim' }, + + config = function() + local harpoon = require 'harpoon' + harpoon:setup() + + vim.keymap.set('n', 'a', function() + harpoon:list():add() + end) + vim.keymap.set('n', '', function() + harpoon.ui:toggle_quick_menu(harpoon:list()) + end) + + vim.keymap.set('n', '', function() + harpoon:list():select(1) + end) + vim.keymap.set('n', '', function() + harpoon:list():select(2) + end) + vim.keymap.set('n', '', function() + harpoon:list():select(3) + end) + vim.keymap.set('n', '', function() + harpoon:list():select(4) + end) + + -- Toggle previous & next buffers stored within Harpoon list + vim.keymap.set('n', '', function() + harpoon:list():prev() + end) + vim.keymap.set('n', '', function() + harpoon:list():next() + end) + + -- basic telescope configuration + local conf = require('telescope.config').values + local function toggle_telescope(harpoon_files) + local file_paths = {} + for _, item in ipairs(harpoon_files.items) do + table.insert(file_paths, item.value) + 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 {}, + }) + :find() + end + + vim.keymap.set('n', '', function() + toggle_telescope(harpoon:list()) + end, { desc = 'Open harpoon window' }) + end, + + --keymaps +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index be0eb9d..0000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} diff --git a/lua/custom/plugins/t b/lua/custom/plugins/t new file mode 100644 index 0000000..ef60adb --- /dev/null +++ b/lua/custom/plugins/t @@ -0,0 +1,20 @@ +-- basic telescope configuration +local conf = require("telescope.config").values +local function toggle_telescope(harpoon_files) + local file_paths = {} + for _, item in ipairs(harpoon_files.items) do + table.insert(file_paths, item.value) + 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({}), + }):find() +end + +vim.keymap.set("n", "", function() toggle_telescope(harpoon:list()) end, + { desc = "Open harpoon window" }) diff --git a/lua/lazy-plugins.lua b/lua/lazy-plugins.lua index 9f3ca2a..5d58ec1 100644 --- a/lua/lazy-plugins.lua +++ b/lua/lazy-plugins.lua @@ -62,7 +62,7 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope!