2024-04-21 01:27:42 +02:00
|
|
|
{lib, ...}: let
|
|
|
|
inherit (lib.options) mkOption;
|
2024-10-06 11:23:01 +02:00
|
|
|
inherit (lib.types) either str listOf attrsOf nullOr submodule;
|
2024-04-21 01:27:42 +02:00
|
|
|
inherit (lib.nvim.config) mkBool;
|
|
|
|
|
2024-08-13 00:27:05 +02:00
|
|
|
mapConfigOptions = {
|
2024-04-21 01:27:42 +02:00
|
|
|
desc = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = "A description of this keybind, to be shown in which-key, if you have it enabled.";
|
|
|
|
};
|
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
action = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The command to execute.";
|
2024-04-21 01:27:42 +02:00
|
|
|
};
|
2024-08-12 02:07:45 +02:00
|
|
|
lua = mkBool false ''
|
|
|
|
If true, `action` is considered to be lua code.
|
|
|
|
Thus, it will not be wrapped in `""`.
|
|
|
|
'';
|
|
|
|
|
|
|
|
silent = mkBool true "Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
|
|
|
|
nowait = mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
|
|
|
|
script = mkBool false "Equivalent to adding <script> to a map.";
|
|
|
|
expr = mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
|
|
|
|
unique = mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
|
|
|
|
noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
|
|
|
|
};
|
2024-08-13 00:27:05 +02:00
|
|
|
|
|
|
|
mapType = submodule {
|
|
|
|
options =
|
|
|
|
mapConfigOptions
|
|
|
|
// {
|
2024-10-06 11:23:01 +02:00
|
|
|
key = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The key that triggers this keybind.";
|
|
|
|
};
|
2024-08-13 00:27:05 +02:00
|
|
|
mode = mkOption {
|
|
|
|
type = either str (listOf str);
|
|
|
|
description = ''
|
|
|
|
The short-name of the mode to set the keymapping for. Passing an empty string is the equivalent of `:map`.
|
|
|
|
|
|
|
|
See `:help map-modes` for a list of modes.
|
|
|
|
'';
|
2024-10-06 11:23:01 +02:00
|
|
|
example = ''`["n" "v" "c"]` for normal, visual and command mode'';
|
2024-08-13 00:27:05 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-06 11:23:01 +02:00
|
|
|
legacyMapOption = mode:
|
2024-08-13 00:27:05 +02:00
|
|
|
mkOption {
|
|
|
|
description = "Mappings for ${mode} mode";
|
2024-10-06 11:23:01 +02:00
|
|
|
type = attrsOf (submodule {
|
|
|
|
options = mapConfigOptions;
|
|
|
|
});
|
2024-08-13 00:27:05 +02:00
|
|
|
default = {};
|
|
|
|
};
|
2024-04-21 01:27:42 +02:00
|
|
|
in {
|
|
|
|
options.vim = {
|
2024-10-06 11:23:01 +02:00
|
|
|
keymaps = mkOption {
|
|
|
|
type = listOf mapType;
|
2024-08-12 02:07:45 +02:00
|
|
|
description = "Custom keybindings.";
|
2024-04-21 01:27:42 +02:00
|
|
|
example = ''
|
2024-10-06 11:23:01 +02:00
|
|
|
vim.keymaps = [
|
|
|
|
{
|
|
|
|
key = "<leader>m";
|
2024-08-12 02:07:45 +02:00
|
|
|
mode = "n";
|
2024-04-21 01:27:42 +02:00
|
|
|
silent = true;
|
2024-10-06 11:23:01 +02:00
|
|
|
action = ":make<CR>";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
key = "<leader>l";
|
|
|
|
mode = ["n" "x"];
|
|
|
|
silent = true;
|
|
|
|
action = "<cmd>cnext<CR>";
|
|
|
|
}
|
|
|
|
];
|
2024-04-21 01:27:42 +02:00
|
|
|
'';
|
2024-10-06 11:23:01 +02:00
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
maps = {
|
|
|
|
normal = legacyMapOption "normal";
|
|
|
|
insert = legacyMapOption "insert";
|
|
|
|
select = legacyMapOption "select";
|
|
|
|
visual = legacyMapOption "visual and select";
|
|
|
|
terminal = legacyMapOption "terminal";
|
|
|
|
normalVisualOp = legacyMapOption "normal, visual, select and operator-pending (same as plain 'map')";
|
|
|
|
|
|
|
|
visualOnly = legacyMapOption "visual only";
|
|
|
|
operator = legacyMapOption "operator-pending";
|
|
|
|
insertCommand = legacyMapOption "insert and command-line";
|
|
|
|
lang = legacyMapOption "insert, command-line and lang-arg";
|
|
|
|
command = legacyMapOption "command-line";
|
2024-04-21 01:27:42 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|