2023-02-20 11:42:13 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
helpers = import ../lib/helpers.nix {inherit lib;};
|
2022-12-29 17:34:47 +00:00
|
|
|
|
2022-09-18 11:19:23 +01:00
|
|
|
mapOption = types.oneOf [
|
|
|
|
types.str
|
|
|
|
(types.submodule {
|
|
|
|
options = {
|
|
|
|
silent = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
nowait = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
script = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Equivalent to adding <script> to a map.";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
expr = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
unique = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
noremap = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "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.";
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
action = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The action to execute.";
|
|
|
|
};
|
|
|
|
|
2023-02-22 23:01:27 +01:00
|
|
|
lua = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
If true, `action` is considered to be lua code.
|
|
|
|
Thus, it will not be wrapped in `""`.
|
|
|
|
'';
|
|
|
|
default = false;
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
2023-02-22 23:01:27 +01:00
|
|
|
|
|
|
|
description = helpers.mkNullOrOption types.str ''
|
|
|
|
A textual description of this keybind, to be shown in which-key, if you have it.
|
|
|
|
'';
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
mapOptions = mode:
|
|
|
|
mkOption {
|
|
|
|
description = "Mappings for ${mode} mode";
|
|
|
|
type = types.attrsOf mapOption;
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
in {
|
2022-09-18 11:19:23 +01:00
|
|
|
options = {
|
|
|
|
maps = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
normal = mapOptions "normal";
|
|
|
|
insert = mapOptions "insert";
|
|
|
|
select = mapOptions "select";
|
|
|
|
visual = mapOptions "visual and select";
|
|
|
|
terminal = mapOptions "terminal";
|
|
|
|
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
|
|
|
|
|
|
|
|
visualOnly = mapOptions "visual only";
|
|
|
|
operator = mapOptions "operator-pending";
|
|
|
|
insertCommand = mapOptions "insert and command-line";
|
|
|
|
lang = mapOptions "insert, command-line and lang-arg";
|
|
|
|
command = mapOptions "command-line";
|
|
|
|
};
|
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
default = {};
|
2022-09-18 11:19:23 +01:00
|
|
|
description = ''
|
|
|
|
Custom keybindings for any mode.
|
|
|
|
|
|
|
|
For plain maps (e.g. just 'map' or 'remap') use maps.normalVisualOp.
|
|
|
|
'';
|
|
|
|
|
|
|
|
example = ''
|
|
|
|
maps = {
|
|
|
|
normalVisualOp.";" = ":"; # Same as noremap ; :
|
|
|
|
normal."<leader>m" = {
|
|
|
|
silent = true;
|
|
|
|
action = "<cmd>make<CR>";
|
|
|
|
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
mappings =
|
|
|
|
(helpers.genMaps "" config.maps.normalVisualOp)
|
|
|
|
++ (helpers.genMaps "n" config.maps.normal)
|
|
|
|
++ (helpers.genMaps "i" config.maps.insert)
|
|
|
|
++ (helpers.genMaps "v" config.maps.visual)
|
|
|
|
++ (helpers.genMaps "x" config.maps.visualOnly)
|
|
|
|
++ (helpers.genMaps "s" config.maps.select)
|
|
|
|
++ (helpers.genMaps "t" config.maps.terminal)
|
|
|
|
++ (helpers.genMaps "o" config.maps.operator)
|
|
|
|
++ (helpers.genMaps "l" config.maps.lang)
|
|
|
|
++ (helpers.genMaps "!" config.maps.insertCommand)
|
|
|
|
++ (helpers.genMaps "c" config.maps.command);
|
|
|
|
in {
|
|
|
|
extraConfigLua = optionalString (mappings != []) ''
|
|
|
|
-- Set up keybinds {{{
|
|
|
|
do
|
|
|
|
local __nixvim_binds = ${helpers.toLuaObject mappings}
|
2022-09-18 11:19:23 +01:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
for i, map in ipairs(__nixvim_binds) do
|
|
|
|
vim.keymap.set(map.mode, map.key, map.action, map.config)
|
2022-09-18 11:19:23 +01:00
|
|
|
end
|
2023-02-20 11:42:13 +01:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
}
|