Skip to content

Commit

Permalink
feat: option to make some triggers show immediately, regardless of ti…
Browse files Browse the repository at this point in the history
…meoutlen
  • Loading branch information
folke committed May 12, 2021
1 parent 342c8cd commit 3a52dc0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ use {
> ❗️ IMPORTANT: the timeout when **WhichKey** opens is controlled by the vim setting [timeoutlen](https://neovim.io/doc/user/options.html#'timeoutlen').
> Please refer to the documentation to properly set it up. Setting it to `0`, will effectively
> always show **WhichKey** immediately, but a setting of `500` (500ms) is probably more appropriate.
>
> ❗️ don't create any keymappings yourself to trigger WhichKey. Unlike with *vim-which-key*, we do this fully automatically.
> Please remove any left-over triggers you might have from using *vim-which-key*.
>
> 🚑 You can run `:checkhealth which_key` to see if there's any conflicting keymaps that will prevent triggering **WhichKey**
WhichKey comes with the following defaults:
Expand Down Expand Up @@ -109,6 +109,8 @@ WhichKey comes with the following defaults:
show_help = true, -- show help message on the command line when the popup is visible
triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specifiy a list manually
triggers_nowait = {}, -- list of triggers, where WhichKey should not wait for timeoutlen and show immediately
-- triggers_nowait = {"<leader>"} -- shows WK immediately when hitting <leader>
}
```

Expand Down
2 changes: 2 additions & 0 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ local defaults = {
show_help = true, -- show a help message in the command line for using WhichKey
triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specifiy a list manually
triggers_nowait = {}, -- list of triggers, where WhichKey should not wait for timeoutlen and show immediately
-- triggers_nowait = {"<leader>"} -- shows WK immediately when hitting <leader>
}

---@type Options
Expand Down
4 changes: 3 additions & 1 deletion lua/which-key/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local M = {}

M.functions = {}
M.operators = {}
M.nowait = {}

function M.setup()
local builtin_ops = require("which-key.plugins.presets").operators
Expand All @@ -21,6 +22,7 @@ function M.setup()
mappings[op] = { name = label, i = { name = "inside" }, a = { name = "around" } }
end
end
for _, t in pairs(Config.options.triggers_nowait) do M.nowait[t] = true end
M.register(mappings, { mode = "n" })
M.register({ i = { name = "inside" }, a = { name = "around" } }, { mode = "v" })
end
Expand Down Expand Up @@ -307,7 +309,7 @@ function M.hook_add(prefix, mode, buf, secret_only)

local mapmode = mode == "v" and "x" or mode
if secret_only ~= true then M.map(mapmode, prefix, cmd, buf, opts) end
M.map(mapmode, prefix .. secret, "<nop>", buf, opts)
if not M.nowait[prefix] then M.map(mapmode, prefix .. secret, "<nop>", buf, opts) end

M.hooked[id] = true
end
Expand Down

0 comments on commit 3a52dc0

Please sign in to comment.