Skip to content

Add support for grouped keys #1063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,11 @@ with `bax` filetype.

#### Keybindings

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}`.
Plugins may be lazy-loaded on the use of keybindings/maps. You can either specify a single keybinding using a string (in which case they are treated as normal mode maps) or a set of keybindings using a table in one of the following formats: >
```lua
{ key, { mode, key }, ... } -- treated as normal mode if mode is not provided
{ mode = key, mode = { key, ... }, ... }
```

### Performing plugin management operations
`packer` exposes the following functions for common plugin management operations. In all of the
Expand Down
10 changes: 6 additions & 4 deletions doc/packer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ the plugin `Else` will only be loaded after the plugin `Baz`, which itself is
only loaded for files with `bax` filetype.

KEYBINDINGS *packer-plugin-keybindings*
Plugins may be lazy-loaded on the use of keybindings/maps. Individual
keybindings are specified under the `keys` key in a plugin specification
either as a string (in which case they are treated as normal mode maps) or a
table in the format `{mode, map}`.
Plugins may be lazy-loaded on the use of keybindings/maps. You can either
specify a single keybinding using a string (in which case they are treated as
normal mode maps) or a set of keybindings using a table in one of the following
formats: >
{ key, { mode, key }, ... } -- treated as normal mode if mode is not provided
{ mode = key, mode = { key, ... }, ... }

LAZY-LOADING *packer-lazy-load*
To optimize startup time, `packer.nvim` compiles code to perform the
Expand Down
19 changes: 18 additions & 1 deletion lua/packer/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,24 @@ local function make_loaders(_, plugins, output_lua, should_profile)
plugin.keys = { plugin.keys }
end
loaders[name].keys = {}
for _, keymap in ipairs(plugin.keys) do

local keys
if vim.tbl_islist(plugin.keys) then
keys = plugin.keys
else
keys = {}
for mode, keymap in pairs(plugin.keys) do
if type(keymap) == 'string' then
table.insert(keys, { mode, keymap })
else
for _, k in ipairs(keymap) do
table.insert(keys, { mode, k })
end
end
end
end

for _, keymap in ipairs(keys) do
if type(keymap) == 'string' then
keymap = { '', keymap }
end
Expand Down