nixeovim/modules/vim/keymap.nix

43 lines
1.2 KiB
Nix
Raw Normal View History

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
{
options.vim.keymap = with lib; {
2024-04-28 01:54:38 +03:00
_validate = mkOption {
# buffer mode lhs rhs
type = with types; attrsOf (attrsOf (attrsOf (either str attrs)));
visible = false;
internal = true;
readOnly = true;
};
2024-04-26 02:08:23 +03:00
set = mkOption {
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 ];
unwrappedModes = lib.flatten (lib.flip map sourceModes (m:
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
));
buf = if buffer == null then "" else buffer;
in
lib.foldl lib.recursiveUpdate { }
(lib.flip map unwrappedModes (m: {
"${buf}"."${m}"."${lhs}" = rhs;
}))
)
cfg.set);
};
2024-04-26 02:08:23 +03:00
}