diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index f0ebd726..d96e4801 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -3,12 +3,11 @@ lib, ... }: let + inherit (builtins) toJSON; inherit (lib.strings) optionalString; - inherit (lib.lists) optional; inherit (lib.modules) mkIf; inherit (lib.meta) getExe; inherit (lib.nvim.binds) mkLznBinding; - inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.terminal.toggleterm; lazygitMapDesc = "Open lazygit [toggleterm]"; @@ -18,12 +17,13 @@ in { lazy.plugins.toggleterm-nvim = { package = "toggleterm-nvim"; cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; - keys = - [(mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal")] - ++ optional cfg.lazygit.enable { + keys = [ + (mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal") + { key = cfg.lazygit.mappings.open; desc = lazygitMapDesc; - }; + } + ]; setupModule = "toggleterm"; inherit (cfg) setupOpts; @@ -42,7 +42,7 @@ in { end }) - vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) + vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) ''; }; }; diff --git a/modules/plugins/utility/surround/config.nix b/modules/plugins/utility/surround/config.nix index 7161cf6b..4ce15cae 100644 --- a/modules/plugins/utility/surround/config.nix +++ b/modules/plugins/utility/surround/config.nix @@ -8,6 +8,19 @@ inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.utility.surround; + vendoredKeybinds = { + insert = "z"; + insert_line = "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; }; @@ -23,33 +36,20 @@ in { inherit (cfg) setupOpts; keys = - [ - (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"]) [ - "(nvim-surround-insert)" - "(nvim-surround-insert-line)" - "(nvim-surround-normal)" - "(nvim-surround-normal-cur)" - "(nvim-surround-normal-line)" - "(nvim-surround-normal-cur-line)" - "(nvim-surround-visual)" - "(nvim-surround-visual-line)" - "(nvim-surround-delete)" - "(nvim-surround-change)" - "(nvim-surround-change-line)" - ]; + 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 + ]); }; + + utility.surround.setupOpts.keymaps = mkIf cfg.useVendoredKeybindings vendoredKeybinds; }; }; } diff --git a/modules/plugins/utility/surround/surround.nix b/modules/plugins/utility/surround/surround.nix index d74966af..7d006381 100644 --- a/modules/plugins/utility/surround/surround.nix +++ b/modules/plugins/utility/surround/surround.nix @@ -1,36 +1,7 @@ -{ - lib, - config, - ... -}: let +{lib, ...}: let inherit (lib.options) mkOption; - inherit (lib.types) bool str; + inherit (lib.types) bool; inherit (lib.nvim.types) mkPluginSetupOption; - - cfg = config.vim.utility.surround; - vendoredKeybinds = { - insert = "z"; - insert_line = "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 { @@ -42,21 +13,7 @@ in { with nvim-leap. ''; }; - setupOpts = mkPluginSetupOption "nvim-surround" { - keymaps = { - insert = mkKeymapOption "insert" "s"; - insert_line = mkKeymapOption "insert_line" "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"; - }; - }; + setupOpts = mkPluginSetupOption "nvim-surround" {}; useVendoredKeybindings = mkOption { type = bool; diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index 61436279..d42e1bbc 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -23,6 +23,7 @@ in { package = "telescope"; setupModule = "telescope"; inherit (cfg) setupOpts; + # FIXME: how do I deal with extensions? set all as deps? after = '' local telescope = require("telescope") ${optionalString config.vim.ui.noice.enable "telescope.load_extension('noice')"} diff --git a/modules/wrapper/lazy/default.nix b/modules/wrapper/lazy/default.nix index 671516b0..fa401272 100644 --- a/modules/wrapper/lazy/default.nix +++ b/modules/wrapper/lazy/default.nix @@ -1,4 +1,4 @@ -{ +_: { imports = [ ./lazy.nix ./config.nix