Compare commits

..

No commits in common. "71727e5378e4e01ae80d2dbc976ef51deb4355d8" and "fd4ddbdd39e34b0f07fc94768f66bacfbb56d050" have entirely different histories.

3 changed files with 37 additions and 66 deletions

View file

@ -4,74 +4,55 @@
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.trivial) pipe; inherit (builtins) mapAttrs;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
legacyMapModes = { processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})];
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; cfg = config.vim;
in { in {
config = { config = {
vim.keymaps = mkMerge [ vim.keymaps = mkMerge [
( (mkIf cfg.disableArrows {
mkIf cfg.disableArrows [ "<up>" = [
{ {
key = "<up>";
mode = ["n" "i"]; mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
} }
];
"<down>" = [
{ {
key = "<down>";
mode = ["n" "i"]; mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
} }
];
"<left>" = [
{ {
key = "<left>";
mode = ["n" "i"]; mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
} }
];
"<right>" = [
{ {
key = "<right>";
mode = ["n" "i"]; mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
} }
] ];
) })
( (mapAttrs (_key: processLegacyMap ["n"]) cfg.maps.normal)
pipe cfg.maps (mapAttrs (_key: processLegacyMap ["i"]) cfg.maps.insert)
[ (mapAttrs (_key: processLegacyMap ["s"]) cfg.maps.select)
(mapAttrsToList ( (mapAttrs (_key: processLegacyMap ["v"]) cfg.maps.visual)
oldMode: keybinds: (mapAttrs (_key: processLegacyMap ["t"]) cfg.maps.terminal)
mapAttrsToList ( (mapAttrs (_key: processLegacyMap ["n" "v" "o"]) cfg.maps.normalVisualOp)
key: bind: (mapAttrs (_key: processLegacyMap ["n" "x"]) cfg.maps.visualOnly)
bind (mapAttrs (_key: processLegacyMap ["o"]) cfg.maps.operator)
// { (mapAttrs (_key: processLegacyMap ["i" "c"]) cfg.maps.insertCommand)
inherit key; (mapAttrs (_key: processLegacyMap ["l"]) cfg.maps.lang)
mode = legacyMapModes.${oldMode}; (mapAttrs (_key: processLegacyMap ["c"]) cfg.maps.command)
}
)
keybinds
))
flatten
]
)
]; ];
}; };
} }

View file

@ -31,12 +31,6 @@
options = options =
mapConfigOptions mapConfigOptions
// { // {
key = mkOption {
type = str;
description = ''
Key that triggers this keybind.
'';
};
mode = mkOption { mode = mkOption {
type = either str (listOf str); type = either str (listOf str);
description = '' description = ''
@ -50,36 +44,31 @@
}; };
# legacy stuff # legacy stuff
legacyMapOption = submodule { mapOption = submodule {
options = mapConfigOptions; options = mapConfigOptions;
}; };
mapOptions = mode: mapOptions = mode:
mkOption { mkOption {
description = "Mappings for ${mode} mode"; description = "Mappings for ${mode} mode";
type = attrsOf legacyMapOption; type = attrsOf mapOption;
default = {}; default = {};
}; };
in { in {
options.vim = { options.vim = {
keymaps = mkOption { keymaps = mkOption {
type = listOf mapType; type = submodule {
freeformType = attrsOf (listOf mapType);
};
description = "Custom keybindings."; description = "Custom keybindings.";
example = '' example = ''
vim.keymaps = [ maps = {
{ "<leader>m" = {
key = "<leader>m";
mode = "n"; mode = "n";
silent = true; silent = true;
action = ":make<CR>"; action = "<cmd>make<CR>";
} }; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
{ };
key = "<leader>l";
mode = ["n" "x"];
silent = true;
action = "<cmd>cnext<CR>";
}
];
''; '';
default = {}; default = {};
}; };

View file

@ -40,14 +40,15 @@ in {
inherit (keymap) desc silent nowait script expr unique noremap; inherit (keymap) desc silent nowait script expr unique noremap;
}; };
toLuaKeymap = bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject bind.key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})"; toLuaKeymap = key: bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
maps = maps =
pipe pipe
# listOf mapOption # attrsOf (listOf mapOption)
cfg.keymaps cfg.keymaps
[ [
(map toLuaKeymap) (mapAttrsToList (key: binds:
concatLines (map (toLuaKeymap key) binds)))
concatLines concatLines
]; ];