2024-04-28 01:54:38 +03:00
|
|
|
{ config, lib, ... }:
|
2024-04-26 02:08:23 +03:00
|
|
|
|
2024-04-28 01:54:38 +03:00
|
|
|
let cfg = config.vim.keymap; in
|
2024-04-26 02:08:23 +03:00
|
|
|
{
|
2024-04-28 00:39:50 +03:00
|
|
|
options.vim.keymap = with lib; {
|
2024-04-28 01:54:38 +03:00
|
|
|
_validate = mkOption {
|
2024-05-01 14:56:36 +03:00
|
|
|
# mode lhs rhs
|
|
|
|
type = with types; attrsOf (attrsOf (either str attrs));
|
2024-04-28 01:54:38 +03:00
|
|
|
visible = false;
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
};
|
2024-04-26 02:08:23 +03:00
|
|
|
set = mkOption {
|
2024-04-28 00:39:50 +03:00
|
|
|
type = with types; listOf keymap;
|
2024-04-26 02:08:23 +03:00
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
};
|
2024-04-28 01:54:38 +03:00
|
|
|
|
|
|
|
config = {
|
|
|
|
vim.keymap._validate = lib.mkMerge
|
|
|
|
(map
|
|
|
|
({ mode, lhs, rhs, buffer, ... }:
|
|
|
|
let
|
|
|
|
sourceModes = if builtins.isList mode then mode else [ mode ];
|
2024-04-29 16:33:51 +03:00
|
|
|
unwrappedModes = lib.unique (lib.flatten (lib.flip map sourceModes (m:
|
2024-04-29 15:47:56 +03:00
|
|
|
if m == "" then [ m "n" "x" "s" "o" ]
|
|
|
|
else if m == "!" then [ m "i" "c" ]
|
|
|
|
else if m == "v" then [ m "x" "s" ]
|
|
|
|
else if m == "l" then [ m "i" "c" "l" ]
|
2024-04-28 01:54:38 +03:00
|
|
|
else m
|
2024-04-29 16:33:51 +03:00
|
|
|
)));
|
2024-04-28 01:54:38 +03:00
|
|
|
in
|
|
|
|
lib.foldl lib.recursiveUpdate { }
|
|
|
|
(lib.flip map unwrappedModes (m: {
|
2024-05-01 14:56:36 +03:00
|
|
|
"${m}"."${lhs}" = rhs;
|
2024-04-28 01:54:38 +03:00
|
|
|
}))
|
|
|
|
)
|
|
|
|
cfg.set);
|
|
|
|
};
|
2024-04-26 02:08:23 +03:00
|
|
|
}
|