nvf/modules/neovim/mappings/config.nix

78 lines
1.5 KiB
Nix
Raw Normal View History

{
config,
lib,
...
}: let
2024-08-18 12:16:44 +00:00
inherit (lib.modules) mkIf mkMerge;
2024-08-23 12:16:07 +00:00
inherit (lib.trivial) pipe;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
2024-08-18 12:16:44 +00:00
2024-08-23 12:16:07 +00:00
legacyMapModes = {
normal = ["n"];
insert = ["i"];
select = ["s"];
visual = ["v"];
terminal = ["t"];
normalVisualOp = ["n" "v" "o"];
visualOnly = ["n" "x"];
operator = ["o"];
insertCommand = ["i" "c"];
lang = ["l"];
command = ["c"];
};
cfg = config.vim;
in {
config = {
2024-08-18 12:16:44 +00:00
vim.keymaps = mkMerge [
2024-08-23 12:16:07 +00:00
(
mkIf cfg.disableArrows [
2024-08-18 12:16:44 +00:00
{
2024-08-23 12:16:07 +00:00
key = "<up>";
2024-08-18 12:16:44 +00:00
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
{
2024-08-23 12:16:07 +00:00
key = "<down>";
2024-08-18 12:16:44 +00:00
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
{
2024-08-23 12:16:07 +00:00
key = "<left>";
2024-08-18 12:16:44 +00:00
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
{
2024-08-23 12:16:07 +00:00
key = "<right>";
2024-08-18 12:16:44 +00:00
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
2024-08-23 12:16:07 +00:00
]
)
(
pipe cfg.maps
[
(mapAttrsToList (
oldMode: keybinds:
mapAttrsToList (
key: bind:
bind
// {
inherit key;
mode = legacyMapModes.${oldMode};
}
)
keybinds
))
flatten
]
)
2024-08-18 12:16:44 +00:00
];
};
}