ThePrimeagen / harpoon

MIT License
7.13k stars 378 forks source link

Unbinding the <CR> binding the harpoon automatically creates breaks Telescope integration #636

Open LukeWood opened 1 month ago

LukeWood commented 1 month ago

Hi - I love harpoon. thanks for making this. It is absolutely incredible for working on features in big projects.

I've found one little use that I haven't been able to resolve. I like to keep my key unbound in normal mode - in particular because I have bindings that I use a LOT to .

Here is my harpoon setup - Notice the first comment, following "--- I'd like to unbind this.". More specifically, if you bind to , the hotkey C-m also stops working for some reason.

Any ideas what could be going on - or a better solution? I'd like to keep bound when the menu is open of course, but I don't like accidentally hitting and having my harpoon menu be toggled back open when I'm just iterating on some code (I mash to iterate through trouble.nvim)

local harpoon = require("harpoon")

harpoon:setup();

-- I'd like to unbind this - but for some reason it
-- breaks harpoon + Telescope
-- vim.keymap.set('n', '<cr>', '<nop>');

-- basic telescope configuration
local conf = require("telescope.config").values

local function toggle_telescope(harpoon_files)
  local make_finder = function()
    local paths = {}
    for _, item in ipairs(harpoon_files.items) do
      table.insert(paths, item.value)
    end

    return require("telescope.finders").new_table(
      {
        results = paths
      }
    )
  end

  require("telescope.pickers").new({}, {
    prompt_title = "Harpoon",
    finder = make_finder(),
    previewer = conf.file_previewer({}),
    sorter = conf.generic_sorter({}),
    attach_Mappings = function(prompt_buffer_number, map)
      map(
        "i",
        "<C-d>", -- your mapping here
        function()
          local state = require("telescope.actions.state")
          local selected_entry = state.get_selected_entry()
          local current_picker = state.get_current_picker(prompt_buffer_number)

          harpoon:list():removeAt(selected_entry.index)
          current_picker:refresh(make_finder())
        end
      )
      return true
    end
  }):find()
end

vim.keymap.set("n", "<C-e>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)

vim.keymap.set("n", "<C-m>", function()
  harpoon:list():add()
  toggle_telescope(harpoon:list())
end)
Lcchy commented 3 weeks ago

Hi @LukeWood, I was facing a similar issue and for me the problem was the keymap of <C-m> to toggle harpoon.

Neovim seems to link <C-m> to <CR> and this interferes.

See #515 and #267

In the end I didn't need to do vim.keymap.set('n', '<cr>', '<nop>'); or vim.keymap.del("n", "<CR>"), using another keymap was enough.

Hope this helps.