Skip to content

Commit d06ab96

Browse files
committed
feat(compile): add support for grouped keys
1 parent 6afb674 commit d06ab96

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,11 @@ with `bax` filetype.
523523

524524
#### Keybindings
525525

526-
Plugins may be lazy-loaded on the use of keybindings/maps. Individual keybindings are specified either as a string (in which case they are treated as normal mode maps) or a table in the format `{mode, map}`.
526+
Plugins may be lazy-loaded on the use of keybindings/maps. Individual keybindings are specified either as a string (in which case they are treated as normal mode maps) or a table in one of the following formats:
527+
```lua
528+
{ key, { mode, key }, ... } -- treated as normal mode if mode is not provided
529+
{ mode = key, mode = { key, ... }, ... }
530+
```
527531

528532
### Performing plugin management operations
529533
`packer` exposes the following functions for common plugin management operations. In all of the

doc/packer.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,10 @@ only loaded for files with `bax` filetype.
388388

389389
KEYBINDINGS *packer-plugin-keybindings*
390390
Plugins may be lazy-loaded on the use of keybindings/maps. Individual
391-
keybindings are specified under the `keys` key in a plugin specification
392-
either as a string (in which case they are treated as normal mode maps) or a
393-
table in the format `{mode, map}`.
391+
keybindings are specified either as a string (in which case they are treated
392+
as normal mode maps) or a table in one of the following formats: >
393+
{ key, { mode, key }, ... } -- treated as normal mode if mode is not provided
394+
{ mode = key, mode = { key, ... }, ... }
394395
395396
LAZY-LOADING *packer-lazy-load*
396397
To optimize startup time, `packer.nvim` compiles code to perform the

lua/packer/compile.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,24 @@ local function make_loaders(_, plugins, output_lua, should_profile)
422422
plugin.keys = { plugin.keys }
423423
end
424424
loaders[name].keys = {}
425-
for _, keymap in ipairs(plugin.keys) do
425+
426+
local keys
427+
if vim.tbl_islist(plugin.keys) then
428+
keys = plugin.keys
429+
else
430+
keys = {}
431+
for mode, keymap in pairs(plugin.keys) do
432+
if type(keymap) == 'string' then
433+
table.insert(keys, { mode, keymap })
434+
else
435+
for _, k in ipairs(keymap) do
436+
table.insert(keys, { mode, k })
437+
end
438+
end
439+
end
440+
end
441+
442+
for _, keymap in ipairs(keys) do
426443
if type(keymap) == 'string' then
427444
keymap = { '', keymap }
428445
end

0 commit comments

Comments
 (0)