Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LukeWood opened this issue Oct 5, 2024 · 1 comment

Comments

@LukeWood
Copy link

LukeWood commented Oct 5, 2024

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
Copy link

Lcchy commented Oct 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants