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
4.76k stars 154 forks source link

bug: Command mode prompt doesn't show until user types, when mapping opens command mode #553

Closed dylan-chong closed 4 hours ago

dylan-chong commented 7 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.9.4

Operating system/version

Ubuntu 22.04.3 LTS

Describe the bug

Command mode prompt is invisible until user types after triggering the mapping, e.g. the example below (which is in the repro lua)

{ ':echo "hello but not pressing enter"', 'example' }

Steps To Reproduce

  1. nvim -u repro.lua
  2. Type <space>%
  3. Nothing will happen.
  4. Type a

Expected Behavior

Command mode should show up at the end of step 2 with cursor at the end of the line

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/which-key.nvim", config = true, init = function()
      require('which-key').register({
          ['%'] = { ':echo "hello but not pressing enter"', 'example' }
      }, { prefix = '<space>' })
  end},
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
dylan-chong commented 5 months ago

For now, i'm working around the issue by using the command mode buffer

function CopyPath(expand)
  local string = vim.fn.expand(expand)
  vim.fn.setreg('+', string)
  print('Copied: ' .. string)
end
lvim.builtin.which_key.mappings['%'] = {
  ":lua CopyPath('%:p')<Left><Left><Left><C-f>i", -- added <C-f>i
  "Copy file path"
}
jonathf commented 5 months ago

I have the same issue on MacOS. Workaround also work, but not with Noice unfortunatly. It forces traditional cmd mode.

github-actions[bot] commented 6 days 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.

dylan-chong commented 6 days ago

still an issue