surround: rework keymap config

This commit is contained in:
Ching Pei Yang 2024-10-31 14:16:46 +01:00
parent 11e0b9a031
commit de6e701386
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
2 changed files with 72 additions and 29 deletions

View file

@ -8,19 +8,6 @@
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.utility.surround; cfg = config.vim.utility.surround;
vendoredKeybinds = {
insert = "<C-g>z";
insert_line = "<C-g>Z";
normal = "gz";
normal_cur = "gZ";
normal_line = "gzz";
normal_cur_line = "gZZ";
visual = "gz";
visual_line = "gZ";
delete = "gzd";
change = "gzr";
change_line = "gZR";
};
mkLznKey = mode: key: { mkLznKey = mode: key: {
inherit key mode; inherit key mode;
}; };
@ -36,20 +23,33 @@ in {
inherit (cfg) setupOpts; inherit (cfg) setupOpts;
keys = keys =
map (mkLznKey ["i"]) (with vendoredKeybinds; [insert insert_line]) [
++ map (mkLznKey ["x"]) (with vendoredKeybinds; [visual visual_line]) (mkLznKey ["i"] cfg.setupOpts.keymaps.insert)
++ map (mkLznKey ["n"]) (with vendoredKeybinds; [ (mkLznKey ["i"] cfg.setupOpts.keymaps.insert_line)
normal (mkLznKey ["x"] cfg.setupOpts.keymaps.visual)
normal_cur (mkLznKey ["x"] cfg.setupOpts.keymaps.visual_line)
normal_line (mkLznKey ["n"] cfg.setupOpts.keymaps.normal)
normal_cur_line (mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur)
delete (mkLznKey ["n"] cfg.setupOpts.keymaps.normal_line)
change (mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur_line)
change_line (mkLznKey ["n"] cfg.setupOpts.keymaps.delete)
]); (mkLznKey ["n"] cfg.setupOpts.keymaps.change)
(mkLznKey ["n"] cfg.setupOpts.keymaps.change_line)
]
++ map (mkLznKey ["n" "i" "v"]) [
"<Plug>(nvim-surround-insert)"
"<Plug>(nvim-surround-insert-line)"
"<Plug>(nvim-surround-normal)"
"<Plug>(nvim-surround-normal-cur)"
"<Plug>(nvim-surround-normal-line)"
"<Plug>(nvim-surround-normal-cur-line)"
"<Plug>(nvim-surround-visual)"
"<Plug>(nvim-surround-visual-line)"
"<Plug>(nvim-surround-delete)"
"<Plug>(nvim-surround-change)"
"<Plug>(nvim-surround-change-line)"
];
}; };
utility.surround.setupOpts.keymaps = mkIf cfg.useVendoredKeybindings vendoredKeybinds;
}; };
}; };
} }

View file

@ -1,7 +1,36 @@
{lib, ...}: let {
lib,
config,
...
}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) bool; inherit (lib.types) bool str;
inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.nvim.types) mkPluginSetupOption;
cfg = config.vim.utility.surround;
vendoredKeybinds = {
insert = "<C-g>z";
insert_line = "<C-g>Z";
normal = "gz";
normal_cur = "gZ";
normal_line = "gzz";
normal_cur_line = "gZZ";
visual = "gz";
visual_line = "gZ";
delete = "gzd";
change = "gzr";
change_line = "gZR";
};
mkKeymapOption = name: default:
mkOption {
description = "keymap for ${name}";
type = str;
default =
if cfg.useVendoredKeybindings
then vendoredKeybinds.${name}
else default;
};
in { in {
options.vim.utility.surround = { options.vim.utility.surround = {
enable = mkOption { enable = mkOption {
@ -13,7 +42,21 @@ in {
with nvim-leap. with nvim-leap.
''; '';
}; };
setupOpts = mkPluginSetupOption "nvim-surround" {}; setupOpts = mkPluginSetupOption "nvim-surround" {
keymaps = {
insert = mkKeymapOption "insert" "<C-g>s";
insert_line = mkKeymapOption "insert_line" "<C-g>S";
normal = mkKeymapOption "normal" "ys";
normal_cur = mkKeymapOption "normal_cur" "yss";
normal_line = mkKeymapOption "normal_line" "yS";
normal_cur_line = mkKeymapOption "normal_cur_line" "ySS";
visual = mkKeymapOption "visual" "S";
visual_line = mkKeymapOption "visual_line" "gS";
delete = mkKeymapOption "delete" "ds";
change = mkKeymapOption "change" "cs";
change_line = mkKeymapOption "change_line" "cS";
};
};
useVendoredKeybindings = mkOption { useVendoredKeybindings = mkOption {
type = bool; type = bool;