ggandor / leap.nvim

Neovim's answer to the mouse 🦘
MIT License
4.33k stars 47 forks source link

Unable to define custom trigger key in NvChad (lazy.vim) #225

Closed Hajneken closed 5 months ago

Hajneken commented 5 months ago

Environment: WSL Ubuntu, NvChad (lazy.vim)

Within my ~/.config/nvim/lua/custom/plugins.lua I am using the suggested Full Spec configuration for leap suggested in the lazy.vim plugins docs.

Problem: I am trying to use, let's say, the \ key for both forward and backward leap. Unfortunately pressing \ is ignored. I tried various other keys, even distinct keys for forward and backward leap without success.

{
    "ggandor/leap.nvim",
    enabled = true,
    keys = {
      { "\\",  mode = { "n", "x", "o" }, desc = "Leap Forward to" },
      { "\\",  mode = { "n", "x", "o" }, desc = "Leap Backward to" },
      { "gs", mode = { "n", "x", "o" }, desc = "Leap from Windows" },
    },
    config = function(_, opts)
      local leap = require("leap")
      for k, v in pairs(opts) do
        leap.opts[k] = v
      end
      leap.add_default_mappings(true)
      vim.keymap.del({ "x", "o" }, "x")
      vim.keymap.del({ "x", "o" }, "X")
    end,
  }

I might have missed something. Frankly I am a bit lost in all the configuration. However, if I put the suggested Full Spec configuration config, it works as expected:

{
  "ggandor/leap.nvim",
  enabled = true,
  keys = {
    { "s", mode = { "n", "x", "o" }, desc = "Leap Forward to" },
    { "S", mode = { "n", "x", "o" }, desc = "Leap Backward to" },
    { "gs", mode = { "n", "x", "o" }, desc = "Leap from Windows" },
  },
  config = function(_, opts)
    local leap = require("leap")
    for k, v in pairs(opts) do
      leap.opts[k] = v
    end
    leap.add_default_mappings(true)
    vim.keymap.del({ "x", "o" }, "x")
    vim.keymap.del({ "x", "o" }, "X")
  end,
}
Hajneken commented 5 months ago

Solved the problem in the meantime. Here's the config that works.

{
    "ggandor/leap.nvim",
    enabled = true,
    keys = {'\\'},
    config = function(_, opts)
      local leap = require("leap")
      for k, v in pairs(opts) do
        leap.opts[k] = v
      end
      leap.add_default_mappings(true)
      vim.keymap.del({ "x", "o" }, "x")
      vim.keymap.del({ "x", "o" }, "X")
      vim.keymap.set({'n','x','o'},'\\','<Plug>(leap)')
    end,
}
ggandor commented 5 months ago

Glad it's solved. However, no need to use keys (https://github.com/ggandor/leap.nvim/issues/191), also, add_default_mappings is deprecated. If you want bidirectional, it's easier to just manually define all mappings anyway, instead of using the helper method and then deleting the unnecessary mappings (https://github.com/ggandor/leap.nvim?tab=readme-ov-file#installation [Alternative key mappings], or :help leap-custom-mappings).