nixeovim/modules/input.nix

61 lines
1.6 KiB
Nix
Raw Normal View History

2024-04-26 02:08:23 +03:00
{ config, lib, ... }:
let
2024-05-08 01:09:18 +03:00
inherit (lib) mod;
2024-04-26 02:08:23 +03:00
cfg = config.input;
2024-05-08 01:30:47 +03:00
disableKeymaps = mode: lhss: lib.flip map lhss (lhs: { inherit mode lhs; rhs = mod.Nop; });
2024-04-26 02:08:23 +03:00
in
{
options.input = with lib; {
leader = mkOption {
type = types.str;
default = ''\'';
2024-05-08 01:30:47 +03:00
apply = x: assert (builtins.stringLength x == 1 || abort "${mod.Leader} `${x}` is longer than one character is not allowed"); x;
};
localLeader = mkOption {
type = types.str;
default = ''\'';
2024-05-08 01:30:47 +03:00
apply = x: assert (builtins.stringLength x == 1 || abort "${mod.LocalLeader} `${x}` is longer than one character is not allowed"); x;
};
exMode.enable = mkEnableOption "Ex mode";
2024-04-26 02:08:23 +03:00
arrowKeys = {
disable = mkOption {
type = types.bool;
default = true;
};
mode = mkOption {
type = types.mode;
default = [ "n" "v" "o" ];
2024-04-26 02:08:23 +03:00
};
};
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.g.maplocalleader = cfg.localLeader;
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
2024-05-08 01:30:47 +03:00
(disableKeymaps cfg.arrowKeys.mode [ mod.Up mod.Down mod.Left mod.Right ])
# Disable PageUp / PageDown
++ lib.optionals cfg.pageButtons.disable
2024-05-08 01:30:47 +03:00
(disableKeymaps cfg.pageButtons.mode [ mod.PageUp mod.PageDown ]);
};
2024-04-26 02:08:23 +03:00
}