nixeovim/modules/input.nix

60 lines
1.6 KiB
Nix

{ config, lib, ... }:
let
inherit (lib) mod;
cfg = config.input;
disableKeymaps = mode: lhss: lib.flip map lhss (lhs: { inherit mode lhs; rhs = mod.Nop; });
in
{
options.input = with lib; {
leader = mkOption {
type = types.str;
default = ''\'';
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 = ''\'';
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";
arrowKeys = {
disable = mkOption {
type = types.bool;
default = true;
};
mode = mkOption {
type = types.mode;
default = [ "n" "v" "o" ];
};
};
pageButtons = {
disable = mkOption {
type = types.bool;
default = true;
};
mode = mkOption {
type = types.mode;
default = [ "" "!" ];
};
};
};
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
(disableKeymaps cfg.arrowKeys.mode [ mod.Up mod.Down mod.Left mod.Right ])
# Disable PageUp / PageDown
++ lib.optionals cfg.pageButtons.disable
(disableKeymaps cfg.pageButtons.mode [ mod.PageUp mod.PageDown ]);
};
}