surround-nvim: lazy load

This commit is contained in:
Ching Pei Yang 2024-10-06 20:13:39 +02:00
commit 4701bb15c5
No known key found for this signature in database
GPG key ID: 062FBBCE1D0C5DD9

View file

@ -8,25 +8,50 @@
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: {
inherit key mode;
};
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = ["nvim-surround"]; startPlugins = ["nvim-surround"];
pluginRC.surround = entryAnywhere "require('nvim-surround').setup(${toLuaObject cfg.setupOpts})"; pluginRC.surround = entryAnywhere "require('nvim-surround').setup(${toLuaObject cfg.setupOpts})";
utility.surround.setupOpts.keymaps = mkIf cfg.useVendoredKeybindings { lazy.plugins = [
insert = "<C-g>z"; {
insert_line = "<C-g>Z"; package = "nvim-surround";
normal = "gz"; setupModule = "nvim-surround";
normal_cur = "gZ"; inherit (cfg) setupOpts;
normal_line = "gzz";
normal_cur_line = "gZZ"; keys =
visual = "gz"; map (mkLznKey ["i"]) (with vendoredKeybinds; [insert insert_line])
visual_line = "gZ"; ++ map (mkLznKey ["x"]) (with vendoredKeybinds; [visual visual_line])
delete = "gzd"; ++ map (mkLznKey ["n"]) (with vendoredKeybinds; [
change = "gzr"; normal
change_line = "gZR"; normal_cur
}; normal_line
normal_cur_line
delete
change
change_line
]);
}
];
utility.surround.setupOpts.keymaps = mkIf cfg.useVendoredKeybindings vendoredKeybinds;
}; };
}; };
} }