nixeovim/lib/mod.nix

83 lines
1.7 KiB
Nix
Raw Normal View History

2024-05-08 01:06:31 +03:00
{ lib }:
let
inherit (builtins) listToAttrs;
inherit (lib) nameValuePair removePrefix removeSuffix;
2024-05-08 01:06:31 +03:00
wrap = val: "<${val}>";
unwrap = val: removePrefix "<" (removeSuffix ">" val);
2024-05-08 01:06:31 +03:00
char = num: wrap "Char-${num}"; # map a character by its decimal, octal or hexadecimal number
shift = key: wrap "S-${unwrap key}"; # shift-key *shift* *<S-*
ctrl = key: wrap "C-${unwrap key}"; # control-key *control* *ctrl* *<C-*
meta = key: wrap "M-${unwrap key}"; # alt-key or meta-key *META* *ALT* *<M-*
super = key: wrap "D-${unwrap key}"; # command-key or "super" key *<D-*
2024-05-08 01:06:31 +03:00
2024-05-08 01:30:47 +03:00
keys = listToAttrs (map (v: nameValuePair v (wrap v)) (
2024-05-08 01:06:31 +03:00
[
2024-05-08 01:30:47 +03:00
"Leader"
"LocalLeader"
"Cmd"
"Plug"
"MouseMove"
2024-05-08 01:06:31 +03:00
2024-05-08 01:30:47 +03:00
"Nul"
"Bs"
"Tab"
2024-05-08 15:43:02 +03:00
"NL"
"CR"
2024-05-08 01:30:47 +03:00
"Esc"
"Space"
2024-05-08 15:43:02 +03:00
"lt"
2024-05-08 01:30:47 +03:00
"Bslash"
"Bar"
"Del"
"Csi"
"Eol"
"Ignore"
"Nop"
"Up"
"Down"
"Left"
"Right"
"Help"
"Undo"
"Insert"
"Home"
"End"
"PageUp"
"PageDown"
2024-05-08 01:06:31 +03:00
"kUp"
"kDown"
"kLeft"
"kRight"
"kHome"
"kEnd"
"kOrigin"
"kPageUp"
"kPageDown"
"kDel"
"kPlus"
"kMinus"
"kMultiply"
"kDivide"
"kPoint"
"kComma"
"kEqual"
"kEnter"
]
++ map (n: "F${toString n}") (lib.range 1 12)
++ map (n: "k${toString n}") (lib.range 0 9)
)
);
in
{ inherit char shift ctrl meta super; } // keys // {
return = keys.cr;
enter = keys.cr;
backslash = keys.bslash;
2024-05-08 01:30:47 +03:00
2024-05-08 15:43:02 +03:00
cmd = expr: keys.Cmd + expr + keys.CR;
2024-05-08 01:30:47 +03:00
leader = expr: keys.Leader + expr;
localLeader = expr: keys.LocalLeader + expr;
2024-05-08 01:06:31 +03:00
}