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;
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: {
inherit key mode;
};
@ -36,20 +23,33 @@ in {
inherit (cfg) setupOpts;
keys =
map (mkLznKey ["i"]) (with vendoredKeybinds; [insert insert_line])
++ map (mkLznKey ["x"]) (with vendoredKeybinds; [visual visual_line])
++ map (mkLznKey ["n"]) (with vendoredKeybinds; [
normal
normal_cur
normal_line
normal_cur_line
delete
change
change_line
]);
[
(mkLznKey ["i"] cfg.setupOpts.keymaps.insert)
(mkLznKey ["i"] cfg.setupOpts.keymaps.insert_line)
(mkLznKey ["x"] cfg.setupOpts.keymaps.visual)
(mkLznKey ["x"] cfg.setupOpts.keymaps.visual_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur_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.types) bool;
inherit (lib.types) bool str;
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 {
options.vim.utility.surround = {
enable = mkOption {
@ -13,7 +42,21 @@ in {
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 {
type = bool;