mappings: add new keymap option

This commit is contained in:
Ching Pei Yang 2024-10-02 01:45:03 +02:00
parent 6670d752c7
commit aff88b8379
No known key found for this signature in database
GPG key ID: 062FBBCE1D0C5DD9

View file

@ -31,6 +31,12 @@
options =
mapConfigOptions
// {
key = mkOption {
type = str;
description = ''
Key that triggers this keybind.
'';
};
mode = mkOption {
type = either str (listOf str);
description = ''
@ -38,27 +44,47 @@
See `:help map-modes` for a list of modes.
'';
example = ''"nvc" for normal, visual and command mode'';
};
};
};
# legacy stuff
mapOption = submodule {
legacyMapOption = submodule {
options = mapConfigOptions;
};
mapOptions = mode:
mkOption {
description = "Mappings for ${mode} mode";
type = attrsOf mapOption;
type = attrsOf legacyMapOption;
default = {};
};
in {
options.vim = {
maps = mkOption {
type = submodule {
freeformType = attrsOf mapType;
options = {
keymaps = mkOption {
type = listOf mapType;
description = "Custom keybindings.";
example = ''
vim.keymaps = [
{
key = "<leader>m";
mode = "n";
silent = true;
action = ":make<CR>";
}
{
key = "<leader>l";
mode = ["n" "x"];
silent = true;
action = "<cmd>cnext<CR>";
}
];
'';
default = {};
};
maps = {
normal = mapOptions "normal";
insert = mapOptions "insert";
select = mapOptions "select";
@ -73,17 +99,4 @@ in {
command = mapOptions "command-line";
};
};
default = {};
description = "Custom keybindings.";
example = ''
maps = {
"<leader>m" = {
mode = "n";
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
'';
};
};
}