docs: Add an FAQ entry for keymap aliases (#1301)

Fixes #1215
This commit is contained in:
Matt Sturgeon 2024-03-22 12:02:49 +00:00 committed by GitHub
parent da7c6c41ef
commit 7a952a4e32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,3 +45,45 @@ When using NixVim it is possible to encounter an error of the type `attribute 'n
This usually means one of two things:
- The nixpkgs version is not in line with NixVim (for example nixpkgs nixos-23.11 is used with NixVim master)
- The nixpkgs unstable version used with NixVim is not recent enough.
## How do I create multiple aliases for a single keymap
You could use the builtin [`map`] function (or similar) to do something like this:
```nix
keymaps =
(builtins.map (key: {
inherit key;
action = "<some-action>";
options.desc = "My cool keymapping";
}) ["<key-1>" "<key-2>" "<key-3>"])
++ [
# Other keymaps...
];
```
This maps a list of keys into a list of similar [`keymaps`]. It is equivalent to:
```nix
keymaps = [
{
key = "<key-1>";
action = "<some-action>";
options.desc = "My cool keymapping";
}
{
key = "<key-2>";
action = "<some-action>";
options.desc = "My cool keymapping";
}
{
key = "<key-3>";
action = "<some-action>";
options.desc = "My cool keymapping";
}
# Other keymaps...
];
```
[`map`]: https://nixos.org/manual/nix/stable/language/builtins#builtins-map
[`keymaps`]: ../keymaps