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.12k stars 163 forks source link

bug: flash.nvim with vim-abolish together will not show the hint for vim-abolish #653

Closed qanyue closed 1 month ago

qanyue commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.11-nightly

Operating system/version

windows11-neovide

Describe the bug

      require("which-key").add({
                mode = { "n" },
                { "cr", group = "vim-abolish variable name style change" },
                { "cr-", desc = "hdash-caseh (aka kebab-case)" },
                { "cr.", desc = " dot.case (not usually reversible; see h: abolish-coercion-reversible)" },
                { "crU", desc = "SNAKE_UPPERCASE" },
                { "cr_", desc = "snake_case" },
                { "crc", desc = "camelCase" },
                { "crk", desc = "kebab-case (not usually reversible; see h: abolish-coercion-reversible)" },
                { "crm", desc = "MixedCase (aka PascalCase)" },
                { "crp", desc = "PascalCase" },
                { "crs", desc = "snake_case" },
                { "cru", desc = "SNAKE_UPPERCASE" },
            })

I add this to show the hint for vim-abolish, and the 'r' represent the remote mode of flash.nvim. The function is working fine. but the which-key will not show for vim-abolish. But it works fine in previous which-key . In previous version . Slow press 'c' and 'r' will active flash.nvim remote mode, quick press 'cr' will active vim-abolish function and which-key will show the hint.

Steps To Reproduce

  1. install the vim-abolish and the flash.nvim
  2. 'r' for remote mode
  3. add config for vim-abolish

Expected Behavior

Slow press 'c' and 'r' will active flash.nvim remote mode, quick press 'cr' will active vim-abolish function and which-key will show the hint.

Health

==============================================================================
which-key: require("which-key.health").check()

- OK Most of these checks are for informational purposes only.
  WARNINGS should be treated as a warning, and don't necessarily indicate a problem with your config.
  Please |DON't| report these warnings as an issue.
- WARNING |mini.icons| is not installed
- OK |nvim-web-devicons| is installed

Checking for issues with your mappings ~
- OK No issues reported

checking for overlapping keymaps ~
- WARNING In mode `x`, <a> overlaps with <ai>, <al>, <a%>, <an>, <aI>, <a,>:
  - <a>: around
  - <ai>: indent
  - <al>: last
  - <an>: next
- WARNING In mode `x`, <i> overlaps with <ii>, <il>, <ih>, <iI>, <in>, <i%>, <i2,>, <i,>:
  - <i>: inside
  - <ii>: indent
  - <il>: last
  - <in>: next
- WARNING In mode `x`, <s> overlaps with <sa>:
  - <s>: Flash
  - <sa>: Add surrounding
- WARNING In mode `o`, <a> overlaps with <ai>, <al>, <a%>, <an>, <aI>, <a,>:
  - <a>: around
  - <ai>: indent
  - <al>: last
  - <an>: next
- WARNING In mode `o`, <i> overlaps with <ii>, <il>, <ih>, <iI>, <in>, <i%>, <i2,>, <i,>:
  - <i>: inside
  - <ii>: indent
  - <il>: last
  - <in>: next
- WARNING In mode `n`, <s> overlaps with <sf>, <sd>, <sh>, <sa>, <sr>, <sn>, <sF>:
  - <s>: Flash
  - <sf>: Find right surrounding
  - <sd>: Delete surrounding
  - <sh>: Highlight surrounding
  - <sa>: Add surrounding
  - <sr>: Replace surrounding
  - <sn>: Update `MiniSurround.config.n_lines`
  - <sF>: Find left surrounding
- WARNING In mode `n`, <[u> overlaps with <[uu>:

- WARNING In mode `n`, <[x> overlaps with <[xx>:

- WARNING In mode `n`, <[y> overlaps with <[yy>:

- WARNING In mode `n`, <[C> overlaps with <[CC>:

- WARNING In mode `n`, <gc> overlaps with <gcc>:
  - <gc>: Comment toggle line
  - <gcc>: Toggle comment line
- WARNING In mode `n`, <gp> overlaps with <gpr>, <gpt>, <gpi>, <gpc>, <gpd>:
  - <gp>: Lspsaga peek definition
- WARNING In mode `n`, <gr> overlaps with <grr>, <grn>, <gra>:
  - <gr>: References
  - <grr>: vim.lsp.buf.references()
  - <grn>: vim.lsp.buf.rename()
  - <gra>: vim.lsp.buf.code_action()
- WARNING In mode `n`, <\p> overlaps with <\pp>:
  - <\pp>: show all telescope commands
- WARNING In mode `n`, <\q> overlaps with <\qq>:

- WARNING In mode `n`, <\t> overlaps with <\ts>, <\tg>, <\tO>, <\tf>, <\tT>, <\tt>, <\to>, <\tw>, <\tb>, <\tS>, <\tr>, <\tl>:
  - <\t>: Explorer NeoTree (root dir)
  - <\ts>: Toggle Summary
  - <\tg>: Neotree show git_status
  - <\tO>: Toggle Output Panel
  - <\tf>: Neotree Focus
  - <\tT>: Run All Test Files
  - <\tt>: Run File
  - <\to>: Show Output
  - <\tw>: Explorer NeoTree current c[w]d
  - <\tb>: Neotree show buffers
  - <\tS>: Stop
  - <\tr>: Explorer NeoTree (file directory)
  - <\tl>: Run Last
- WARNING In mode `n`, <]u> overlaps with <]uu>:

- WARNING In mode `n`, <]x> overlaps with <]xx>:

- WARNING In mode `n`, <]y> overlaps with <]yy>:

- WARNING In mode `n`, <]C> overlaps with <]CC>:

- WARNING In mode `n`, <\fr> overlaps with <\frw>:
  - <\fr>: mru
  - <\frw>: Mru Current work dir
- WARNING In mode `n`, <\fp> overlaps with <\fpd>:
  - <\fp>: [F]ind project
  - <\fpd>: [F]ind  recent project
- WARNING In mode `n`, <<SNR>68_> overlaps with <<SNR>68_(save-cursor-pos)>:

- OK Overlapping keymaps are only reported for informational purposes.
  This doesn't necessarily mean there is a problem with your config.

Checking for duplicate mappings ~
- OK No duplicate mappings found

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",
            lazy = false,
            init = function()
                vim.o.timeout = true
                vim.o.timeoutlen = 300
            end,
            opts = {
                ---@type false | "classic" | "modern" | "helix"
                preset = "classic",
                -- Delay before showing the popup. Can be a number or a function that returns a number.
                ---@type number | fun(ctx: { keys: string, mode: string, plugin?: string }):number
                delay = function(ctx)
                    return ctx.plugin and 0 or 386
                end,
                specs = {
                    { "cr", group = "vim-abolish variable name style change" },
                },
                plugins = {
                    registers = true,
                },
                icons = {
                    rules = false,
                },
            },
        },
        {
            "folke/flash.nvim",
            event = "VeryLazy",
            ---@type Flash.Config
            opts = {
                modes = {
                    -- options used when flash is activated through
                    -- `f`, `F`, `t`, `T`, `;` and `,` motions
                    char = {
                        enabled = false,
                        -- dynamic configuration for ftFT motions
                        config = function(opts)
                            -- autohide flash when in operator-pending mode
                            opts.autohide = vim.fn.mode(true):find "no" and vim.v.operator == "y"

                            -- disable jump labels when enabled and when using a count
                            opts.jump_labels = opts.jump_labels and vim.v.count == 0

                            -- Show jump labels only in operator-pending mode
                            -- opts.jump_labels = vim.v.count == 0 and vim.fn.mode(true):find("o")
                        end,
                        -- hide after jump when not using jump labels
                        autohide = false,
                        -- show jump labels
                        jump_labels = false,
                        -- set to `false` to use the current line only
                        multi_line = false,
                        -- When using jump labels, don't use these keys
                        -- This allows using those keys directly after the motion
                        label = { exclude = "hjkliardc" },
                        -- by default all keymaps are enabled, but you can disable some of them,
                        -- by removing them from the list.
                        -- If you rather use another key, you can map them
                        -- to something else, e.g., { [";"] = "L", [","] = H }
                        keys = { "f", "F", "t", "T", ";", "," },
                        ---@alias Flash.CharActions table<string, "next" | "prev" | "right" | "left">
                        -- The direction for `prev` and `next` is determined by the motion.
                        -- `left` and `right` are always left and right.
                        char_actions = function(motion)
                            return {
                                [";"] = "next", -- set to `right` to always go right
                                [","] = "prev", -- set to `left` to always go left
                                -- clever-f style
                                [motion:lower()] = "next",
                                [motion:upper()] = "prev",
                                -- jump2d style: same case goes next, opposite case goes prev
                                -- [motion] = "next",
                                -- [motion:match("%l") and motion:upper() or motion:lower()] = "prev",
                            }
                        end,
                        search = { wrap = false },
                        highlight = { backdrop = true },
                        jump = { register = false },
                    },
                    treesitter = {
                        label = {
                            rainbow = {
                                enabled = true,
                                -- number between 1 and 9
                                shade = 5,
                            },
                        },
                    },
                },
            },
            keys = {
                {
                    "s",
                    mode = { "n", "o", "x" },
                    function()
                        require("flash").jump()
                    end,
                    desc = "Flash",
                },
                {
                    "<cr>",
                    mode = { "n" },
                    function()
                        require("flash").jump { continue = true }
                    end,
                    desc = "Flash",
                },
                {
                    "S",
                    mode = { "n", "o", "x" },
                    function()
                        require("flash").treesitter()
                    end,
                    desc = "Flash Treesitter",
                },
                {
                    "r",
                    mode = "o",
                    function()
                        require("flash").remote()
                    end,
                    desc = "Remote Flash", -- 复制时回到原位置
                },
                {
                    "R",
                    mode = { "o", "x" },
                    function()
                        require("flash").treesitter_search()
                    end,
                    desc = "Treesitter Search",
                },
                {
                    "<c-s>",
                    mode = { "c" },
                    function()
                        require("flash").toggle()
                    end,
                    desc = "Toggle Flash Search",
                },
            },
        },
        {
            "tpope/vim-abolish",
            cmd = { "Abolish", "S", "Subvert" },
            keys = { "cr" },
            event = { "BufReadPost", "BufNewFile", "BufWritePre" },
            init = function()
                require("which-key").add {
                    mode = { "n" },
                    { "cr", group = "vim-abolish variable name style change" },
                    { "cr-", desc = "hdash-caseh (aka kebab-case)" },
                    { "cr.", desc = " dot.case (not usually reversible; see h: abolish-coercion-reversible)" },
                    { "crU", desc = "SNAKE_UPPERCASE" },
                    { "cr_", desc = "snake_case" },
                    { "crc", desc = "camelCase" },
                    { "crk", desc = "kebab-case (not usually reversible; see h: abolish-coercion-reversible)" },
                    { "crm", desc = "MixedCase (aka PascalCase)" },
                    { "crp", desc = "PascalCase" },
                    { "crs", desc = "snake_case" },
                    { "cru", desc = "SNAKE_UPPERCASE" },
                }
                --
            end,
        },

        -- add any other plugins here
    },
}
qanyue commented 1 month ago

english is not my first language , description will has some difficult for me , you can ask any information you need

folke commented 1 month ago

Can you please update the repro:

qanyue commented 1 month ago

Can you please update the repro:

  • remove that utils that I dont have
  • add flash and the mappings
  • make sure you can reproduce it using the repro

my bad , i will update .Please wait a second

qanyue commented 1 month ago

already update the repro, please check it and which-key's commit "0099511294f16b81c696004fa6a403b0ae61f7a0" work fine .

folke commented 1 month ago

So it's fixed then?

folke commented 1 month ago

Allright, I get it now. This is not possible.

cr is a real keymap belonging to vim-abolish.

Which-key no longer overrides the c keymaps and hooks into visual and operator pending modes using ModeChanged.

So what you're looking is no longer possible.

However, what you could do though, is add a mapping for require("which-key").show("cr") like cr? for example. Or if you don' use the cr mapping itself, you can just override that one