NotAShelf / nvf

A highly modular, extensible and distro-agnostic Neovim configuration framework for Nix/NixOS.
https://notashelf.github.io/nvf/
MIT License
158 stars 26 forks source link

vim.maps rewrite #304

Open diniamo opened 3 months ago

diniamo commented 3 months ago

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

🏷️ 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 = "...";
}
ppenguin commented 1 month ago

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.

horriblename commented 1 month ago

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 = "...";}
};
NotAShelf commented 1 month ago

["n", "v"]

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

diniamo commented 1 month ago

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 commented 1 month ago

@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.

horriblename commented 1 month ago

heh I misread

horriblename commented 1 month ago

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

diniamo commented 1 month ago

Make vim.maps a list then, idk