142 lines
4.5 KiB
Nix
142 lines
4.5 KiB
Nix
|
{ lib, ... }:
|
||
|
|
||
|
let
|
||
|
modeType = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ];
|
||
|
|
||
|
# TODO: maybe add more options and add descriptions from
|
||
|
# :help vim.keymap.set
|
||
|
# :help nvim_set_keymap
|
||
|
setKeymapType = with lib; with types; submodule {
|
||
|
options = {
|
||
|
lhs = mkOption {
|
||
|
type = str;
|
||
|
description = ''
|
||
|
Left-hand side |{lhs}| of the mapping.
|
||
|
'';
|
||
|
};
|
||
|
rhs = mkOption {
|
||
|
type = oneOf [ str attrs ];
|
||
|
description = ''
|
||
|
Right-hand side |{rhs}| of the mapping, can be a Lua function.
|
||
|
'';
|
||
|
};
|
||
|
mode = mkOption {
|
||
|
type = oneOf [
|
||
|
modeType
|
||
|
(uniq (listOf modeType))
|
||
|
];
|
||
|
default = "";
|
||
|
description = ''
|
||
|
Mode | Norm | Ins | Cmd | Vis | Sel | Opr | Term | Lang |
|
||
|
Command +------+-----+-----+-----+-----+-----+------+------+
|
||
|
"" | yes | - | - | yes | yes | yes | - | - |
|
||
|
"n" | yes | - | - | - | - | - | - | - |
|
||
|
"!" | - | yes | yes | - | - | - | - | - |
|
||
|
"i" | - | yes | - | - | - | - | - | - |
|
||
|
"c" | - | - | yes | - | - | - | - | - |
|
||
|
"v" | - | - | - | yes | yes | - | - | - |
|
||
|
"x" | - | - | - | yes | - | - | - | - |
|
||
|
"s" | - | - | - | - | yes | - | - | - |
|
||
|
"o" | - | - | - | - | - | yes | - | - |
|
||
|
"t" | - | - | - | - | - | - | yes | - |
|
||
|
"l" | - | yes | yes | - | - | - | - | yes |
|
||
|
|
||
|
`:help map-overview`
|
||
|
'';
|
||
|
};
|
||
|
buffer = mkOption {
|
||
|
type = nullOr str;
|
||
|
default = null;
|
||
|
description = ''
|
||
|
The mapping will be effective in the current buffer only.
|
||
|
|
||
|
`:help :map-buffer`
|
||
|
'';
|
||
|
};
|
||
|
nowait = mkOption {
|
||
|
type = bool;
|
||
|
default = false;
|
||
|
description = ''
|
||
|
When defining a buffer-local mapping for "," there may be a global mapping
|
||
|
that starts with ",". Then you need to type another character for Vim to know
|
||
|
whether to use the "," mapping or the longer one. To avoid this add the
|
||
|
<nowait> argument. Then the mapping will be used when it matches, Vim does
|
||
|
not wait for more characters to be typed.
|
||
|
|
||
|
`:help :map-nowait`
|
||
|
'';
|
||
|
};
|
||
|
silent = mkOption {
|
||
|
type = bool;
|
||
|
default = false;
|
||
|
description = ''
|
||
|
To define a mapping which will not be echoed on the command line.
|
||
|
|
||
|
`:help :map-silent`
|
||
|
'';
|
||
|
};
|
||
|
script = mkOption {
|
||
|
type = bool;
|
||
|
default = false;
|
||
|
description = ''
|
||
|
If the first argument to one of these commands is "<script>" and it is used to
|
||
|
define a new mapping or abbreviation, the mapping will only remap characters
|
||
|
in the {rhs} using mappings that were defined local to a script, starting with
|
||
|
"<SID>". This can be used to avoid that mappings from outside a script
|
||
|
interfere (e.g., when CTRL-V is remapped in mswin.vim), but do use other
|
||
|
mappings defined in the script.
|
||
|
|
||
|
`:help :map-script`
|
||
|
'';
|
||
|
|
||
|
};
|
||
|
expr = mkOption {
|
||
|
type = bool;
|
||
|
default = false;
|
||
|
description = ''
|
||
|
If the first argument to one of these commands is "<expr>" and it is used to
|
||
|
define a new mapping or abbreviation, the argument is an expression. The
|
||
|
expression is evaluated to obtain the {rhs} that is used.
|
||
|
|
||
|
`:help :map-expression`
|
||
|
'';
|
||
|
};
|
||
|
unique = mkOption {
|
||
|
type = bool;
|
||
|
default = false;
|
||
|
description = ''
|
||
|
It is used to define a new mapping or abbreviation, the command will fail if
|
||
|
the mapping or abbreviation already exists.
|
||
|
|
||
|
When defining a local mapping, there will also be a check if a global map
|
||
|
already exists which is equal.
|
||
|
|
||
|
`:help :map-unique`
|
||
|
'';
|
||
|
};
|
||
|
remap = mkOption {
|
||
|
type = bool;
|
||
|
default = false;
|
||
|
description = ''
|
||
|
Make the mapping recursive.
|
||
|
'';
|
||
|
};
|
||
|
desc = mkOption {
|
||
|
type = nullOr str;
|
||
|
default = null;
|
||
|
description = ''
|
||
|
Human-readable description.
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
in
|
||
|
{
|
||
|
options.vim.keymap = with lib; with types; {
|
||
|
set = mkOption {
|
||
|
type = listOf setKeymapType;
|
||
|
default = [ ];
|
||
|
};
|
||
|
};
|
||
|
}
|