nixeovim/modules/input.nix

58 lines
1.6 KiB
Nix
Raw Normal View History

2024-04-26 02:08:23 +03:00
{ config, lib, ... }:
let
cfg = config.input;
disableKeymaps = mode: lhss: lib.flip map lhss (lhs: { inherit mode lhs; rhs = "<nop>"; });
in
{
options.input = with lib; {
leader = mkOption {
type = types.str;
default = ''\'';
apply = x: assert (builtins.stringLength x == 1 || abort "<Leader> `${x}` is longer than one character is not allowed"); x;
};
localLeader = mkOption {
type = types.str;
default = ''\'';
apply = x: assert (builtins.stringLength x == 1 || abort "<LocalLeader> `${x}` is longer than one character is not allowed"); x;
};
2024-04-26 02:08:23 +03:00
exMode.enable = (mkEnableOption "Ex mode") // { default = true; };
arrowKeys = {
disable = mkOption {
type = types.bool;
default = true;
};
mode = mkOption {
type = types.mode;
2024-04-26 02:08:23 +03:00
default = [ "n" "v" ];
};
};
pageButtons = {
disable = mkOption {
type = types.bool;
default = true;
};
mode = mkOption {
type = types.mode;
default = "";
2024-04-26 02:08:23 +03:00
};
};
};
config = {
vim.g.mapleader = cfg.leader;
vim.keymap.set =
# Disable the annoying and useless ex-mode
lib.optionals (!cfg.exMode.enable) (disableKeymaps "n" [ "Q" "gQ" ])
# Disable arrow keys
++ lib.optionals cfg.arrowKeys.disable
(disableKeymaps cfg.arrowKeys.mode [ "<Up>" "<Down>" "<Left>" "<Right>" ])
# Disable PageUp / PageDown
++ lib.optionals cfg.pageButtons.disable
(disableKeymaps cfg.pageButtons.mode [ "<PageUp>" "<PageDown>" ]);
};
2024-04-26 02:08:23 +03:00
}