which-key.nvim
which-key.nvim copied to clipboard
Show groups between mappings
Is there a way to inline the group names between the mappings?
a -> mapping
b -> +group
c -> mapping 2
instead of
a -> mapping
c -> mapping 2
b -> +group
I was looking for similar functionality and came across https://github.com/folke/which-key.nvim/issues/131. Probably these 2 issues are duplicates, or at least related. It'd be nice if there was a way to control the order in which the mappings are displayed. For me, just having the ability to disable the auto-ordering and let the mappings be displayed as they have been declared would be enough.
If the sorting function would be configurable function() return false end should keep manual sorting.
I forked the repo and was able to suppress the sorting without too much trouble. Then added a configuration option to toggle sorting on and off and that worked as well. But when trying out this solution and actually inspecting the order of the keys, I found they were different every time.
I think the issue is the fact that in Lua the sequence of keys is only guaranteed for tables with integer keys. My source is this SO post where it says:
In Lua, only tables with 1-based consecutive integer keys (a.k.a. array tables) can be parsed in order.
But until a few days ago I hadn't written a line of Lua in my life, so I might be way off.
In any case, the fix seems to be less trivial than I initially thought and I'm in over my head.
I'm not a 100% sure but if it works ipairs would have to be used instead of pairs.
I don’t see how that would help since the keys are still strings and not integers.
Right, doesn't work with ipairs.
Providing a custom sorting function would however work.
I can't think of a solution which is based on how the keys are inserted (i.e. the lexical sequence in which the mappings were written). A Lua table is passed to the register function, and the table data type does not respect insertion order. So the order is lost straight away.
I can see how a "custom sorting" function could help, but only if the mappings had some explicit property to sort on. For example if a mapping would accept a order_nr property. Personally, if I would have to choose between the two evils of managing the order of my key mappings this way, or having them auto-sorted alphabetically, I'd probably go with the latter option.
I'm deleting my cloned repo and will not be pursuing this any further.
Well, this ticket was about sorting groups alongside mappings. This can be done by a custom sort function.
Preserving the order could only work with a order_id or by using register multiple times (where the order of the calls would be preserved).
You could also use a sort function where you store an array table and compare the indices. But you'd again have to have second list - should be reasonably easy to generate this list with sed though.
should be reasonably easy to generate this list with
sedthough
That sounds like an interesting approach! Good luck.
This would be great to have -- having two aA-zZ lists (one for X mappings + another for the +X group names) instead of just one is the one thing that's always looked strange when using this plugin.