Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ When `desc`, `group`, or `icon` are functions, they are evaluated every time
the popup is shown.

The `expand` property allows to create dynamic mappings. Only functions as `rhs` are supported for dynamic mappings.
Two examples are included in `which-key.extras`:
Three examples are included in `which-key.extras`:

- `require("which-key.extras").expand.buf`: creates numerical key to buffer mappings
- `require("which-key.extras").expand.tab`: creates numerical key to tab mappings
- `require("which-key.extras").expand.win`: creates numerical key to window mappings

```lua
Expand Down
19 changes: 19 additions & 0 deletions lua/which-key/extras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,23 @@ function M.expand.win()
return M.add_keys(ret)
end

function M.expand.tab()
local ret = {}
local current = vim.api.nvim_get_current_tabpage()
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
if tab ~= current then
local num = vim.api.nvim_tabpage_get_number(tab)
ret[#ret + 1] = {
"",
function ()
vim.api.nvim_set_current_tabpage(tab)
end,
desc = "Goto tab " .. tostring(num),
icon = { cat = "file", name = tostring(num) },
}
end
end
return M.add_keys(ret)
end

return M
Loading