nvf icon indicating copy to clipboard operation
nvf copied to clipboard

vim.maps rewrite

Open diniamo opened this issue 1 year ago • 8 comments

⚠️ Please verify that this feature request has NOT been suggested before.

  • [X] I checked and didn't find a similar feature request

🏷️ Feature Type

Other

🔖 Feature description

The current implementation isn't great, because the implementation is messy, and it's not flexible, since the user can't specify modes.

✔️ Solution

My suggestion is very similar to the previous one, except binds are directly in vim.maps and there is a new mode attribute in their definition, eg.:

vim.maps."..." = {
  mode = "n";
  action = "...";
};

(mode is of type either str (listOf str))

❓ Alternatives

No response

📝 Additional Context

This would still allow the user to have a very similar structure, eg.:

vim.maps = builtins.mapAttrs (_: value: { mode = "n"; } // value) {
  "...".action = "...";
}

diniamo avatar Jun 12 '24 14:06 diniamo

It would be cool if mode would be a string that allows multiple modes, such as modes = "niv" for normal, insert, visual. I believe I've used something similar before in nixvim and the UX is much better than having to inherit functions from lib and use e.g. vim.maps.normal = lib.mkMerge [ (mkBinding ....) ... ]; and then the same for other maps. listOf str is unnecessarily verbose, because modes can be indicated by a single letter, so we gain nothing by that.

ppenguin avatar Aug 17 '24 15:08 ppenguin

something like this maybe?

vim.maps = {
  "<leader>x" = [
    {mode = ["n", "v"]; action = ":foo<CR>";}
    {mode = "i"; action = "<cmd>bar<cr>";}
  ];
  
  "<leader>y" = {mode = "c"; action = "...";}
};

horriblename avatar Aug 17 '24 19:08 horriblename

["n", "v"]

ah yes, the infamous comma in a Nix list...

NotAShelf avatar Aug 17 '24 20:08 NotAShelf

something like this maybe?

vim.maps = {
  "<leader>x" = [
    {mode = ["n", "v"]; action = ":foo<CR>";}
    {mode = "i"; action = "<cmd>bar<cr>";}
  ];
  
  "<leader>y" = {mode = "c"; action = "...";}
};

what am I looking at

diniamo avatar Aug 17 '24 20:08 diniamo

@ppenguin I'm pretty sure there is a map mode whose short form is 2 characters, and besides, a list makes more sense, as that's used in the lua api too.

diniamo avatar Aug 17 '24 20:08 diniamo

heh I misread

horriblename avatar Aug 17 '24 20:08 horriblename

though the current rewrite has the problem of not being able to make different bindings for the same key on different modes (what I suggested)

that aside, string (e.g. "nvc" for normal + visual + command) mode should work with this rewrite

p.s. whoever thought comma-less list is good syntax deserves to stub their toe tonight

horriblename avatar Aug 17 '24 20:08 horriblename

Make vim.maps a list then, idk

diniamo avatar Aug 17 '24 20:08 diniamo

#352 #360

diniamo avatar Oct 10 '24 20:10 diniamo