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

bug: which-key hydra mode not working? #906

Open
4 tasks done
ingenarel opened this issue Dec 8, 2024 · 6 comments
Open
4 tasks done

bug: which-key hydra mode not working? #906

ingenarel opened this issue Dec 8, 2024 · 6 comments
Labels
bug Something isn't working stale

Comments

@ingenarel
Copy link

Did you check docs and existing issues?

  • I have read all the which-key.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of which-key.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.11.0-dev-1315+g668d2569b4

Operating system/version

linux

Describe the bug

the docs tell me to do this:

require("which-key").show({
    keys = "<c-w>",                                                                                                                       
    loop = true, -- this will keep the popup open until you hit <esc>                                                                     
})

but when i actually put in my config, i get this error:

Error detected while processing /home/ingenarel/.config/nvim/init.lua:                                                                          
E5113: Error while calling lua chunk: .../share/nvim/plugged/which-key.nvim/lua/which-key/buf.lua:69: attempt to index field 'modes' (a nil valu
e)                                                                                                                                              
stack traceback:                                                                                                                                
        .../share/nvim/plugged/which-key.nvim/lua/which-key/buf.lua:69: in function 'attach'                                                    
        .../share/nvim/plugged/which-key.nvim/lua/which-key/buf.lua:138: in function 'update'                                                   
        .../share/nvim/plugged/which-key.nvim/lua/which-key/buf.lua:52: in function 'new'                                                       
        .../share/nvim/plugged/which-key.nvim/lua/which-key/buf.lua:188: in function 'get'                                                      
        ...hare/nvim/plugged/which-key.nvim/lua/which-key/state.lua:288: in function 'start'                                                    
        ...share/nvim/plugged/which-key.nvim/lua/which-key/init.lua:18: in function 'show'                                                      
        .../ingenarel/.config/nvim/lua/_plugins_/_load-plugins_.lua:91: in main chunk                                                           
        [C]: in function 'require'                                                                                                              
        /home/ingenarel/.config/nvim/init.lua:103: in main chunk

Steps To Reproduce

copy paste this in the config:

require("which-key").show({
    keys = "<c-w>",                                                                                                                       
    loop = true, -- this will keep the popup open until you hit <esc>                                                                     
})

Expected Behavior

the error shouldn't happen?

Health

No response

Log

No response

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/which-key.nvim", opts = {} },
    -- add any other plugins here
  },
})
require("which-key").show({
    keys = "<c-w>",                                                                                                                       
    loop = true, -- this will keep the popup open until you hit <esc>                                                                     
})
@ingenarel ingenarel added the bug Something isn't working label Dec 8, 2024
@edwardbaeg
Copy link

edwardbaeg commented Dec 16, 2024

I had the same issue. I figured out that the correct usage of this is for it to be the lhs rhs of a mapping:

      vim.keymap.set("n", "<c-w><space>", function()
         require("which-key").show({
            keys = "<c-w>",
            loop = true,
         })
      end)

@ingenarel
Copy link
Author

i'm just currently using this function in my config:

---@nodoc CK_Submap_n() {{{1
---@nodoc docs {{{2
---### creates submaps
---uses |nvim_set_keymap| for setting the keymaps
---@param keymap string keymap that you want to set it to.
---@param action string stuff you want to do for the keymap
---@param submaplevel string if your keymap is is `abcd` and you want to just hit `d` after doing `abcd` to execute the keymap again, your submaplevel would be `abc`
---@param opts? {wk: boolean?, desc:string?, wait:integer?, mode:string?} --
---`wk:` nil and true are treated the same -> it executes whichkey before executing the keymap again. if false, it doesn't
---`desc:` the description from the keymap
---`wait:` time to wait before executing the keymap again. uses |vim.wait()|
---`mode`: the mode. normal mode, visual mode, insert mode etc.
---@nodoc docs }}}2
function CK_Submap(keymap, action, submaplevel, opts)
    if opts == nil then
        opts = {}
    end

    local iswhichkey = opts.wk
    local description = opts.desc
    local waiting_time = opts.wait
    local mode = opts.mode

    ---@type string
    local whichkey = ""

    ---@type string
    local wait = ""

    if iswhichkey == true or iswhichkey == nil then
        whichkey = ":WhichKey<lt>CR>"
    end

    if waiting_time ~= nil and waiting_time >= 1 then
        wait = "vim.wait(" .. waiting_time .. ") "
    end

    if mode == nil then
        mode = "n"
    end

    vim.api.nvim_set_keymap(
        mode,
        keymap,
        action
            .. ":lua "
            .. wait
            .. "vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('"
            .. whichkey
            .. submaplevel
            .. "', true, false, true), 'nt', false)<CR>",
        {
            noremap = true,
            silent = true,
            desc = description,
        }
    )
end -- }}}1

@Thorhian
Copy link

I had the same issue. I figured out that the correct usage of this is for it to be the lhs of a mapping:

      vim.keymap.set("n", "<c-w><space>", function()
         require("which-key").show({
            keys = "<c-w>",
            loop = true,
         })
      end)

How do you use it when you are using which-key.add for your mappings already though? I've been trying to make a nested window so that I can make stepping lines in a debugger much less tedious but I have not been able to figure out how to use .show or it's loop parameter correctly in tandom with the standard .add hotkeys and the default trigger. This plugin has been wonderful but the documentation has been lacking. Been trying to look at the source code for answers but no luck yet.

@LintaoAmons
Copy link

have the same issue

@winkee01
Copy link

winkee01 commented Jan 7, 2025

show() function won't work and prompts errors.
the only way to make hydra mode work is to set keys options, as below:

{
  "folke/which-key.nvim",
  event = "VeryLazy",
  ...
  keys = {
      {
        "<c-w><space>",
        function()
          require("which-key").show({ keys = "<c-w>", loop = true })
        end,
        desc = "Window Hydra Mode (which-key)",
      },
  },

Copy link
Contributor

github-actions bot commented Feb 7, 2025

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.

@github-actions github-actions bot added the stale label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

5 participants