folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.58k stars 350 forks source link

feature: Plugin spec keys, grouping keymappings to provide a general name #754

Closed GijsGroote closed 1 year ago

GijsGroote commented 1 year ago

Did you check the docs?

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

Grouping custom keymappings:

Example with true-zen:

Currently adding 2 keymaps

{
    "Pocco81/true-zen.nvim",
    keys = {
        { "<leader>tm", "<Cmd>TZMinimalist<CR>", desc = "minimilist"},
        { "<leader>ta", "<Cmd>TZAtaraxis<CR>", desc = "ataraxis"},
    },
  },

Could these be grouped? Something like this:

{
    "Pocco81/true-zen.nvim",
    keys = {
        { "<leader>t", {
            { "m", "<Cmd>TZMinimalist<CR>", desc = "minimilist"},
            { "a", "<Cmd>TZAtaraxis<CR>", desc = "ataraxis"},
        }, desc = "zen modes"
    },
  },

Mainly I want which-key to provide a general name instead of +prefix.

If I overlooked something in the docs and this is already possible, my apologies in advance. Otherwise, I would gladly like this feature, in that case. Thanks in advance.

Describe the solution you'd like

Grouping keys and giving them a general name.

Describe alternatives you've considered

Whichkey has an build en method which is nice:

This does not support lazy loading.

Example in which key config:

      local function normal_keymap()

        local n_keymap = {
          -- Markdown preview
          md = { [[ <Cmd>MarkdownPreview<CR> ]], "Markdown preview" },

          -- TODO: put this in .tex files only
          -- popup fuzzy bibtex citation finder
          ci = {[[ <Cmd>Telescope bibtex<CR> ]], "Fuzzy citation finder"},

          -- harpoon to navigate between multiple scripts 
          h = { [[<Cmd>lua require("harpoon.mark").add_file()<CR><Cmd>lua print("file harpooned!")<CR>]], "harpoon file"},
          H = { [[ <Cmd>lua require("harpoon.ui").toggle_quick_menu()<CR> ]], "Show harponed files"},
          ["1"] = { [[ <Cmd>lua require("harpoon.ui").nav_file(1)<CR> ]], "goto file 1"},
          ["2"] = { [[ <Cmd>lua require("harpoon.ui").nav_file(2)<CR> ]], "goto file 2"},
          ["3"] = { [[ <Cmd>lua require("harpoon.ui").nav_file(3)<CR> ]], "goto file 3"},
          ["4"] = { [[ <Cmd>lua require("harpoon.ui").nav_file(4)<CR> ]], "goto file 4"},
        }
        whichkey.register(n_keymap)
      end

Additional context

I am fairly new with lazy (and nvim), take this issue request with grains of salt

max397574 commented 1 year ago

you could quite easily write a function to which you can pass a table like this and then return it for the plugin spec

so you can do like keys=parse_mappings(the table)

folke commented 1 year ago

Not interested in having this kind of functionality in lazy