folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
5.12k stars 163 forks source link

feature: subheadings or similar inside a group #786

Closed snoblenet closed 1 month ago

snoblenet commented 1 month ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

Could there be a way to define subheadings or similar inside a group?

I'm looking for a more visually appealing alternative to:

local g_group = {
  { 'g', group = 'Go To / Format Inside Motion' },
  -- Go To
  { 'ge', desc = 'Go To: End Of Previous Word' },
  { 'gf', desc = 'Go To: File Under Cursor' },
  { 'gg', desc = 'Go To: First Line' },
  { 'gi', desc = 'Go To: Last Insert' },
  { 'gn', desc = 'Go To: Next Search Match' },
  { 'gN', desc = 'Go To: Previous Search Match' },
  { 'gt', desc = 'Go To: Next Tab' },
  { 'gT', desc = 'Go To: Previous Tab' },
  { 'gv', desc = 'Go To: Last Visual Selection' },
  -- Format Inside Motion
  { 'gu', desc = 'Format Motion: Lowercase' },
  { 'gU', desc = 'Format Motion: Uppercase' },
  { 'gq', desc = 'Format Motion: Default' },
  { 'gw', desc = 'Format Motion: Default & Return' },
}

Describe the solution you'd like

The ability to do something like:

local g_group = {
  { 'g', group = 'Go To / Format Inside Motion' },
  -- Go To
  { 'ge', heading = 'Go To', desc = End Of Previous Word' },
  { 'gf', heading = 'Go To', desc = 'File Under Cursor' },
  { 'gg', heading = 'Go To', desc = 'First Line' },
  { 'gi', heading = 'Go To', desc = 'Last Insert' },
  { 'gn', heading = 'Go To', desc = 'Next Search Match' },
  { 'gN', heading = 'Go To', desc = 'Previous Search Match' },
  { 'gt', heading = 'Go To', desc = 'Next Tab' },
  { 'gT', heading = 'Go To', desc = 'Previous Tab' },
  { 'gv', heading = 'Go To', desc = 'Last Visual Selection' },
  -- Format Inside Motion
  { 'gu', heading = 'Format Inside Motion', desc = 'Lowercase' },
  { 'gU', heading = 'Format Inside Motion', desc = 'Uppercase' },
  { 'gq', heading = 'Format Inside Motion', desc = 'Default' },
  { 'gw', heading = 'Format Inside Motion', desc = 'Default & Return' },
}

I can't think of another way to structure this without running into duplicate keys in the Lua table.

Describe alternatives you've considered

I tried:

local g_group = {
  -- Go To
  { 'ge', group = 'Go To', desc = End Of Previous Word' },
  { 'gf', group = 'Go To', desc = 'File Under Cursor' },
  { 'gg', group = 'Go To', desc = 'First Line' },
  { 'gi', group = 'Go To', desc = 'Last Insert' },
  { 'gn', group = 'Go To', desc = 'Next Search Match' },
  { 'gN', group = 'Go To', desc = 'Previous Search Match' },
  { 'gt', group = 'Go To', desc = 'Next Tab' },
  { 'gT', group = 'Go To', desc = 'Previous Tab' },
  { 'gv', group = 'Go To', desc = 'Last Visual Selection' },
  -- Format Inside Motion
  { 'gu', group = 'Format Inside Motion', desc = 'Lowercase' },
  { 'gU', group = 'Format Inside Motion', desc = 'Uppercase' },
  { 'gq', group = 'Format Inside Motion', desc = 'Default' },
  { 'gw', group = 'Format Inside Motion', desc = 'Default & Return' },
}

Naturally, it did not work.

Additional context

The treesitter context plug is also adding to the g group, with functions that are neither about "going to" or about "formatting inside a motion".

The g group window is getting very full.

For my own utility, I'm trying to make these lists as scannable and readable as possible.

folke commented 1 month ago

not possible and also not interested in adding this

sid-6581 commented 1 month ago

@snoblenet I've done something similar with some trickery in my config, since I also like to visually scan my keymaps quickly. In my case I mainly identify which plugin they're from, it looks like this:

image

I had to take different approaches for different plugins, and I'm still not quite done, but you can take a look at my config here to see what I did:

https://github.com/sid-6581/NeovimConfig/blob/main/lua/plugins/which-key.lua