diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index d96e4801..f0ebd726 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -3,11 +3,12 @@ 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]"; @@ -17,13 +18,12 @@ 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") - { + keys = + [(mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal")] + ++ optional cfg.lazygit.enable { key = cfg.lazygit.mappings.open; desc = lazygitMapDesc; - } - ]; + }; setupModule = "toggleterm"; inherit (cfg) setupOpts; @@ -42,7 +42,7 @@ in { end }) - vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) + vim.keymap.set('n', ${toLuaObject 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 4ce15cae..7161cf6b 100644 --- a/modules/plugins/utility/surround/config.nix +++ b/modules/plugins/utility/surround/config.nix @@ -8,19 +8,6 @@ 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; }; @@ -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"]) [ + "(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)" + ]; }; - - 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 7d006381..d74966af 100644 --- a/modules/plugins/utility/surround/surround.nix +++ b/modules/plugins/utility/surround/surround.nix @@ -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 = "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 { @@ -13,7 +42,21 @@ in { with nvim-leap. ''; }; - setupOpts = mkPluginSetupOption "nvim-surround" {}; + 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"; + }; + }; useVendoredKeybindings = mkOption { type = bool; diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index d42e1bbc..61436279 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -23,7 +23,6 @@ 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 fa401272..671516b0 100644 --- a/modules/wrapper/lazy/default.nix +++ b/modules/wrapper/lazy/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./lazy.nix ./config.nix