Skip to content

Commit

Permalink
fix(wk)!: Tweaked config, fixed style and inconsistent rules.
Browse files Browse the repository at this point in the history
Signed-off-by: Guennadi Maximov C <[email protected]>
  • Loading branch information
DrKJeff16 committed Aug 24, 2024
1 parent 3e45cb8 commit 76b8686
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions lua/plugin/which_key/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,59 @@ local WK = require('which-key')

WK.setup({
---@type false|'classic'|'modern'|'helix'
preset = 'classic',
preset = 'modern',
-- 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 50 end,
delay = function(ctx) return ctx.plugin and 0 or 100 end,
--- You can add any mappings here, or use `require('which-key').add()` later
---@type wk.Spec
spec = {
{
'<leader>?',
function() WK.show({ global = false }) end,
desc = 'Buffer Local Keymaps (which_key)',
noremap = true,
noremap = false,
buffer = 0,
nowait = true,
silent = true,
},
},

-- Start hidden and wait for a key to be pressed before showing the popup
-- Only used by enabled xo mapping modes.
---@param ctx { mode: string, operator: string }
defer = function(ctx)
local deferred_keys = {
local deferred_modes = {
'o',
'v',
'V',
'<C-v>',
'<C-V>',
'<C-e>',
'<ESC>',
}
return vim.tbl_contains(deferred_keys, ctx.mode)
return vim.tbl_contains(deferred_modes, ctx.mode)
end,

---@param mapping wk.Mapping
filter = function(mapping)
-- example to exclude mappings without a description
-- return mapping.desc and mapping.desc ~= ""
return true
end,

-- show a warning when issues were detected with your mappings
notify = true,

-- Enable/disable WhichKey for certain mapping modes
plugins = {
marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
-- No actual key bindings are created
spelling = {
enabled = false, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
suggestions = 0, -- how many suggestions should be shown in the list?
enabled = vim.opt.spell:get(), -- enabling this will show WhichKey when pressing z= to select spelling suggestions
suggestions = 10, -- how many suggestions should be shown in the list?
},
presets = {
operators = true, -- adds help for operators like d, y, ...
Expand All @@ -74,28 +79,31 @@ WK.setup({
g = true, -- bindings for prefixed with g
},
},

---@type wk.Win
---@diagnostic disable-next-line:missing-fields
win = {
-- width = { min = 30, max = 50 },
-- width = { min = math.floor(vim.opt.columns:get() * 2 / 3 ), max = math.floor(vim.opt.columns:get() * 3 / 4) },
-- height = { min = 4, max = 25 },
-- col = 0,
-- row = 0,
fixed = true,
no_overlap = true,
no_overlap = false,
border = 'rounded',
padding = { 1, 2 }, -- extra window padding [top/bottom, right/left]
title = true,
title_pos = 'center',
zindex = 1000,
-- Additional vim.wo and vim.bo options
bo = {},
bo = {
modifiable = false,
},
wo = {
winblend = in_console() and 0 or 30, -- value between 0-100 0 for fully opaque and 100 for fully transparent
winblend = in_console() and 0 or 15, -- value between 0-100 0 for fully opaque and 100 for fully transparent
},
},
layout = {
width = { min = 20, max = math.floor(vim.opt_local.columns:get() * 2 / 3) }, -- min and max width of the columns
width = { min = 20, max = math.floor(vim.opt_local.columns:get() * 3 / 4) }, -- min and max width of the columns
spacing = 2, -- spacing between columns
align = 'center', -- align columns left, center or right
},
Expand All @@ -113,12 +121,12 @@ WK.setup({
--- * mod: special modifier keys last
--- * manual: the order the mappings were added
--- * case: lower-case first
sort = { 'local', 'alphanum', 'order', 'manual', 'group', 'mod' },
sort = { 'local', 'order', 'case', 'alphanum', 'manual', 'group', 'mod' },
-- expand = 0, -- expand groups when <= n mappings
expand = function(node)
return not node.desc -- expand all nodes without a description
end,
---@type table<string, ({[1]: string, [2]: string}|fun(str:string): string)[]>
---@type table<string, ({ [1]: string, [2]: string }|fun(str: string): string)[]>
replace = {
key = {
function(key) return require('which-key.view').format(key) end,
Expand Down Expand Up @@ -160,12 +168,15 @@ WK.setup({
C = 'CTRL-',
M = '󰘵 ',
S = '󰘶 ',
CR = '󰌑 ',
Esc = '󱊷 ',
-- CR = '󰌑 ',
CR = '<CR>',
-- Esc = '󱊷 ',
Esc = 'ESC ',
ScrollWheelDown = '󱕐 ',
ScrollWheelUp = '󱕑 ',
NL = '󰌑 ',
BS = '',
-- NL = '󰌑 ',
NL = '\\n ',
BS = '',
-- Space = '󱁐 ',
Space = 'SPC ',
-- Tab = '󰌒 ',
Expand All @@ -184,16 +195,19 @@ WK.setup({
F12 = '󱊶',
},
},

show_help = true, -- show a help message in the command line for using WhichKey
show_keys = true, -- show the currently pressed key and its label as a message in the command line

-- Which-key automatically sets up triggers for your mappings.
-- But you can disable this and setup the triggers yourself.
-- Be aware, that triggers are not needed for visual and operator pending mode.
---@type wk.Spec
triggers = {
{ '<auto>', mode = 'nxsot' },
{ '<auto>', mode = { 'n', 'x', 's', 'o', 't', 'v' } },
{ '<leader>', mode = { 'n', 'v' } },
},

disable = {
-- disable WhichKey for certain buf types and file types.
ft = {},
Expand Down

0 comments on commit 76b8686

Please sign in to comment.