diff --git a/docs/user-guide/faq.md b/docs/user-guide/faq.md index ee33c111..41e90ad4 100644 --- a/docs/user-guide/faq.md +++ b/docs/user-guide/faq.md @@ -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 = ""; + options.desc = "My cool keymapping"; + }) ["" "" ""]) + ++ [ + # Other keymaps... + ]; +``` + +This maps a list of keys into a list of similar [`keymaps`]. It is equivalent to: + +```nix +keymaps = [ + { + key = ""; + action = ""; + options.desc = "My cool keymapping"; + } + { + key = ""; + action = ""; + options.desc = "My cool keymapping"; + } + { + key = ""; + action = ""; + options.desc = "My cool keymapping"; + } + # Other keymaps... +]; +``` + +[`map`]: https://nixos.org/manual/nix/stable/language/builtins#builtins-map +[`keymaps`]: ../keymaps