Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim.maps rewrite #304

Open
1 task done
diniamo opened this issue Jun 12, 2024 · 8 comments
Open
1 task done

vim.maps rewrite #304

diniamo opened this issue Jun 12, 2024 · 8 comments

Comments

@diniamo
Copy link
Collaborator

diniamo commented Jun 12, 2024

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

  • 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 = "...";
}
@ppenguin
Copy link
Contributor

ppenguin commented Aug 17, 2024

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
Copy link
Collaborator

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
Copy link
Owner

NotAShelf commented Aug 17, 2024

["n", "v"]

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

@diniamo
Copy link
Collaborator Author

diniamo commented Aug 17, 2024

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
Copy link
Collaborator Author

diniamo commented Aug 17, 2024

@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
Copy link
Collaborator

heh I misread

@horriblename
Copy link
Collaborator

horriblename commented Aug 17, 2024

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
Copy link
Collaborator Author

diniamo commented Aug 17, 2024

Make vim.maps a list then, idk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants