Skip to content

Commit

Permalink
feat: allow overriding key labels #77
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 18, 2021
1 parent ec1474b commit 2be929e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ WhichKey comes with the following defaults:
-- add operators that will trigger motion and text object completion
-- to enable all native operators, set the preset / operators plugin above
operators = { gc = "Comments" },
key_labels = {
-- override the label used to display some keys. It doesn't effect WK in any other way.
-- For example:
-- ["<space>"] = "SPC",
-- ["<cr>"] = "RET",
-- ["<tab>"] = "TAB",
},
icons = {
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
separator = "", -- symbol used between a key and it's label
Expand Down
7 changes: 7 additions & 0 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ local defaults = {
-- add operators that will trigger motion and text object completion
-- to enable all native operators, set the preset / operators plugin above
operators = { gc = "Comments" },
key_labels = {
-- override the label used to display some keys. It doesn't effect WK in any other way.
-- For example:
-- ["<space>"] = "SPC",
-- ["<cr>"] = "RET",
-- ["<tab>"] = "TAB",
},
motions = {
count = true,
},
Expand Down
3 changes: 3 additions & 0 deletions lua/which-key/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ function M.get_mappings(mode, prefix, buf)
for _, value in pairs(ret.mappings) do
value.key = value.keys.nvim[prefix_len + 1]
value.key = vim.fn.strtrans(value.key)
if Config.options.key_labels[value.key] then
value.key = Config.options.key_labels[value.key]
end
local skip = not value.label and Config.options.ignore_missing == true
if Util.t(value.key) == Util.t("<esc>") then
skip = true
Expand Down

0 comments on commit 2be929e

Please sign in to comment.