diff --git a/README.md b/README.md index 35f3d114..8e7ccb79 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/which-key/extras.lua b/lua/which-key/extras.lua index a89ef7e0..a8459201 100644 --- a/lua/which-key/extras.lua +++ b/lua/which-key/extras.lua @@ -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