gbprod / yanky.nvim

Improved Yank and Put functionalities for Neovim
Do What The F*ck You Want To Public License
852 stars 21 forks source link

Unable to use default telescope keymap <c-k> #194

Open kekscode opened 1 month ago

kekscode commented 1 month ago

I am in a try-and-error loop mapping <c-k> in i mode for navigating the picker items, but the <c-k> keeps pasting the selected item no matter what mapping i try to apply in my settings.

My use case is: I use <c-k> and <c-j> in all my telescope pickers to move up/down the picker items and press <cr> to select. This works everywhere (built-in plugins and additional plugins).

Somehow yanky seems to break the mapping of <c-k> in all configurations i tried (minimal, explicitely re-mapping, applying the defaults, etc.).

Any idea what i am doing wrong or what i overlook? Or maybe an issue with keymap merging logic?

My configs:

yanky (full):

  {
    {
      "gbprod/yanky.nvim",
      enabled = true,
      dependencies = {
        { "kkharji/sqlite.lua" }
      },
      opts = {
        ring = { storage = "sqlite" },
      },
      setup = function()
        local utils = require("yanky.utils")
        local mapping = require("yanky.telescope.mapping")

        require("yanky").setup({
          ring = {
            history_length = 200,
            sync_with_numbered_registers = true,
            cancel_event = "update",
            ignore_registers = { "_" },
            update_register_on_cycle = false,
          },
          system_clipboard = {
            sync_with_ring = true,
          },
          picker = {
            select = {
              action = nil, -- nil to use default put action
            },
            telescope = {
              use_default_mappings = true, -- if default mappings should be used
              mappings = {
                default = mapping.put("p"),
                i = {
                  -- FIXME: <c-k> default mapping in telescope does not work for some reason
                  -- <c-j> works as usual, though.
                  --
                  -- Things i tested:
                  -- ["<c-k>"] = require("telescope.actions").move_selection_previous,
                  -- ["<c-k>"] = mapping.select_prev_item,
                  -- ["<c-k>"] = mapping.select_prev_entry,
                  ["<c-p>"] = mapping.put("p"),
                  ["<cr>"] = mapping.put("p"),
                  ["<c-d>"] = mapping.delete(),
                  ["<c-r>"] = mapping.set_register(utils.get_default_register()),
                },
                n = {
                  p = mapping.put("p"),
                  P = mapping.put("P"),
                  d = mapping.delete(),
                  r = mapping.set_register(utils.get_default_register())
                },
              }
            },
          },
        })
      end
    }
  },

telescope (very long, only mappings):

-- [...]
          mappings = {
            -- map actions.which_key to <C-h> (default: <C-/>)
            -- actions.which_key shows the mappings for your picker,
            -- e.g. git_{create, delete, ...}_branch for the git_branches picker
            n = {
              ["<C-b>"] = {
                require("telescope.actions").preview_scrolling_up,
                type = "action",
                opts = { nowait = true, silent = true },
              },
              ["<C-f>"] = {
                require("telescope.actions").preview_scrolling_down,
                type = "action",
                opts = { nowait = true, silent = true },
              },
              ["<C-s>"] = {
                require("telescope.actions").select_horizontal,
                type = "action",
                opts = { nowait = true, silent = true },
              },
            },
            i = {
              ["<C-b>"] = {
                require("telescope.actions").preview_scrolling_up,
                type = "action",
                opts = { nowait = true, silent = true },
              },
              ["<C-f>"] = {
                require("telescope.actions").preview_scrolling_down,
                type = "action",
                opts = { nowait = true, silent = true },
              },
              ["<C-k>"] = {
                require("telescope.actions").move_selection_previous,
                type = "action",
                opts = { nowait = true, silent = true },
              },
              ["<C-j>"] = {
                require("telescope.actions").move_selection_next,
                type = "action",
                opts = { nowait = true, silent = true },
              },
              ["<C-d>"] = {
                -- A bit hacky, because it is useful for the buffer picker but
                -- the mapping is active in all pickers:
                require("telescope.actions").delete_buffer,
                type = "action",
                opts = { nowait = true, silent = true },
              },
            },
          },
        },
-- [...]
gbprod commented 1 month ago

I think you should not use default mappings (set use_default_mappings to false) and just adapt default mappings to your needs (refer to documentation: https://github.com/gbprod/yanky.nvim?tab=readme-ov-file#pickertelescopeuse_default_mappings)

kekscode commented 1 month ago

I did this (and tried again), but <c-k> still pastes what is currently selected in the picker window in the line above the cursor. I think i have to dive a bit deeper into the code. I currently suspect that the custom mappings do not work at all in my config.

What irritates me is, that the telescope config works for every other plugin and for the builtins completely fine.

Is there a good way to debug mappings with e.g. print statements or the like?

kekscode commented 1 month ago

Pretty sure now, that the custom mappings do not get applied at all, even with use_default_mappings as false. The function yank_history.attach_mappings(_, map) looks good, though i am not used to lua code apart from config tables. But i don't see an issue and this is the only function which could lead to a problem. I wonder if i have something crazy in my config which has a side effect or shadows my custom config with the defaults. Is there a way to print the effective configuration table of yanky at runtime? Something like vim.inspect?

kekscode commented 4 weeks ago

I changed this now and get a different telescope window:

+vim.api.nvim_set_keymap("n", "<leader>y", '<cmd>YankyRingHistory<cr>',
-vim.api.nvim_set_keymap("n", "<leader>y", '<cmd>lua require("telescope").extensions.yank_history.yank_history({ })<cr>',

and in this window, <c-k just works.