folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
5.27k stars 165 forks source link

bug: Bindings not honoring mode #542

Closed bagnaram closed 2 months ago

bagnaram commented 10 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.2

Operating system/version

Fedora 39

Describe the bug

I am unable to get the following keymap descriptions to be captured by which-key. I have read a bit about how modes are handled, however the following bindings below aren't being shown in the which-key dialogue.

init.vim:

" copy into system buffer
xnoremap <leader>y "+y
nnoremap <leader>Y "+Y

which-key.lua

local wk = require("which-key")

wk.register({
  f = {
    name = "file", -- optional group name
    f = { "<cmd>Telescope find_files<cr>", "Find File" }, -- create a binding with label
    r = { "<cmd>Telescope oldfiles sort_lastused=true ignore_current_buffer=true <cr>", "Open Recent File", noremap=false},

    -- additional options for creating the keymap
    n = { "New File" }, -- just a label. don't create any mapping
    e = "Edit File", -- same as above
    ["1"] = "which_key_ignore",  -- special label to hide it in the popup
    b = { function() print("bar") end, "Foobar" } -- you can also pass functions!
  },
  g = {
    name = "Neogit",
    mode={'n', 'x'},
    g = { "status" },
    l = { "Copy git permalink to clipboard", mode={'n', 'x'}},
    L = { "Copy git permalink to clipboard", mode={'n', 'x'}},

  },
  p = {
    name = "Project",
    p = { "projects" },
    s = { function() require("telescope.builtin").grep_string({
      search = vim.fn.input("Grep > " ) })
   end, "find" }
  },
  s = {
    name = "Search",
    f = { "<cmd>Telescope find_files<cr>", "Search File Names" }, -- create a binding with label
    p = { "<cmd>Telescope grep_string<cr>", "Search Project" },
  },
  o = {
    name = "Open",
    p = { "projects" }
  },
  b = {
    name = "Buffers",
    b = { "list" },
    k = { "kill" }
  },
  Y = {
    name = "Yank line to system buffer",
    mode = 'n'
  },
  ["<"] = "buffers",
},
{
  prefix = "<leader>",
  mode = 'n'
})

wk.register({
  ['y'] = {
    name = "Yank to system buffer"
  },
},
{
  mode = 'x',
  prefix = "<leader>"
})

Steps To Reproduce

  1. Create the following keymaps in init.vim
  2. Add the following mapping definitions to whick-key
  3. Source configs and enter visual mode and press <LEADER>
  4. Bindings aren't picked up in the dialogue.

Expected Behavior

I should see the keymaps

Repro

N/A
github-actions[bot] commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

bagnaram commented 2 months ago

please remove stale tag

folke commented 2 months ago

Fixed in v3 https://github.com/folke/which-key.nvim/pull/624