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 = 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 = ''
@ -38,27 +44,47 @@
See `:help map-modes` for a list of modes. See `:help map-modes` for a list of modes.
''; '';
example = ''"nvc" for normal, visual and command mode'';
}; };
}; };
}; };
# legacy stuff # legacy stuff
mapOption = submodule { legacyMapOption = submodule {
options = mapConfigOptions; options = mapConfigOptions;
}; };
mapOptions = mode: mapOptions = mode:
mkOption { mkOption {
description = "Mappings for ${mode} mode"; description = "Mappings for ${mode} mode";
type = attrsOf mapOption; type = attrsOf legacyMapOption;
default = {}; default = {};
}; };
in { in {
options.vim = { options.vim = {
maps = mkOption { keymaps = mkOption {
type = submodule { type = listOf mapType;
freeformType = attrsOf mapType; description = "Custom keybindings.";
options = { 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"; normal = mapOptions "normal";
insert = mapOptions "insert"; insert = mapOptions "insert";
select = mapOptions "select"; select = mapOptions "select";
@ -73,17 +99,4 @@ in {
command = mapOptions "command-line"; 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>
};
'';
};
};
} }