From 09695f4fd435ed7f8b8263e36bf7e3fe83823da2 Mon Sep 17 00:00:00 2001 From: Joseph Hanson Date: Fri, 7 Feb 2025 20:24:46 -0600 Subject: [PATCH] feat: add multicursors-nvim plugin multicursors-nvim with hydra dependency and static config. --- configuration.nix | 6 + flake.lock | 34 +++++ flake.nix | 10 ++ modules/plugins/hydra/config.nix | 50 ++++++++ modules/plugins/hydra/default.nix | 6 + modules/plugins/hydra/hydra.nix | 8 ++ modules/plugins/utility/default.nix | 1 + .../plugins/utility/multicursors/config.nix | 68 ++++++++++ .../plugins/utility/multicursors/default.nix | 6 + .../utility/multicursors/multicursors.nix | 17 +++ .../utility/multicursors/multicursors.nix.bak | 120 ++++++++++++++++++ 11 files changed, 326 insertions(+) create mode 100644 modules/plugins/hydra/config.nix create mode 100644 modules/plugins/hydra/default.nix create mode 100644 modules/plugins/hydra/hydra.nix create mode 100644 modules/plugins/utility/multicursors/config.nix create mode 100644 modules/plugins/utility/multicursors/default.nix create mode 100644 modules/plugins/utility/multicursors/multicursors.nix create mode 100644 modules/plugins/utility/multicursors/multicursors.nix.bak diff --git a/configuration.nix b/configuration.nix index 594e292f..a1a68fa4 100644 --- a/configuration.nix +++ b/configuration.nix @@ -181,6 +181,12 @@ isMaximal: { leap.enable = true; precognition.enable = isMaximal; }; + multicursors = { + enable = true; + setupOpts = { + DEBUG_MODE = true; + }; + }; images = { image-nvim.enable = false; diff --git a/flake.lock b/flake.lock index 8e5a40d7..6bc81640 100644 --- a/flake.lock +++ b/flake.lock @@ -727,6 +727,22 @@ "type": "github" } }, + "plugin-hydra-nvim": { + "flake": false, + "locked": { + "lastModified": 1735234935, + "narHash": "sha256-kgwkxeHcJfh0+I9cMix2M83Cp289sJX/BO81+VOp/sU=", + "owner": "nvimtools", + "repo": "hydra.nvim", + "rev": "983852960cd4e4e9a1b272df0bd1447495aae755", + "type": "github" + }, + "original": { + "owner": "nvimtools", + "repo": "hydra.nvim", + "type": "github" + } + }, "plugin-icon-picker-nvim": { "flake": false, "locked": { @@ -1624,6 +1640,22 @@ "type": "github" } }, + "plugin-multicursors-nvim": { + "flake": false, + "locked": { + "lastModified": 1723130615, + "narHash": "sha256-t5FKPwRx1PsU6HboZPx2sMVjU46AKb0nMfoFMpqesss=", + "owner": "smoka7", + "repo": "multicursors.nvim", + "rev": "562809aaf203b4c65482a75199166d360f2b9298", + "type": "github" + }, + "original": { + "owner": "smoka7", + "repo": "multicursors.nvim", + "type": "github" + } + }, "plugin-neo-tree-nvim": { "flake": false, "locked": { @@ -2823,6 +2855,7 @@ "plugin-haskell-tools-nvim": "plugin-haskell-tools-nvim", "plugin-highlight-undo": "plugin-highlight-undo", "plugin-hop-nvim": "plugin-hop-nvim", + "plugin-hydra-nvim": "plugin-hydra-nvim", "plugin-icon-picker-nvim": "plugin-icon-picker-nvim", "plugin-image-nvim": "plugin-image-nvim", "plugin-indent-blankline": "plugin-indent-blankline", @@ -2879,6 +2912,7 @@ "plugin-mini-visits": "plugin-mini-visits", "plugin-minimap-vim": "plugin-minimap-vim", "plugin-modes-nvim": "plugin-modes-nvim", + "plugin-multicursors-nvim": "plugin-multicursors-nvim", "plugin-neo-tree-nvim": "plugin-neo-tree-nvim", "plugin-neocord": "plugin-neocord", "plugin-neodev-nvim": "plugin-neodev-nvim", diff --git a/flake.nix b/flake.nix index eb7f5904..6f6c8d11 100644 --- a/flake.nix +++ b/flake.nix @@ -965,5 +965,15 @@ url = "github:echasnovski/mini.visits"; flake = false; }; + + plugin-hydra-nvim = { + url = "github:nvimtools/hydra.nvim"; + flake = false; + }; + + plugin-multicursors-nvim = { + url = "github:smoka7/multicursors.nvim"; + flake = false; + }; }; } diff --git a/modules/plugins/hydra/config.nix b/modules/plugins/hydra/config.nix new file mode 100644 index 00000000..e117cae9 --- /dev/null +++ b/modules/plugins/hydra/config.nix @@ -0,0 +1,50 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + cfg = config.vim.hydra; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = []; + lazy.plugins.hydra = { + package = "hydra-nvim"; + setupModule = "hydra"; + #inherit (cfg) setupOpts; + setupOpts = { + debug = false; + exit = false; + foreign_keys = null; + color = "red"; + timeout = false; + invoke_on_body = false; + hint = { + show_name = true; + position = "bottom"; + offset = 0; + float_opts = {}; + }; + on_enter = null; + on_exit = null; + on_key = null; + }; + + after = '' + -- custom lua code to run after plugin is loaded + print('multicursors loaded') + ''; + + event = ["DeferredUIEnter"]; + cmd = ["MCstart" "MCvisual" "MCclear" "MCpattern" "MCvisualPattern" "MCunderCursor"]; + }; + #keys = [ + # (mkKeymap "n" mappings.mcStart "MCstart" {desc = "Create a selection for selected text or word under the cursor [multicursors.nvim]";}) + #]; + # dependencies = [ + # config.vim.lazy.plugins.hydra # hydra.nvim - Create custom submodes and menus + # ]; + }; + }; +} diff --git a/modules/plugins/hydra/default.nix b/modules/plugins/hydra/default.nix new file mode 100644 index 00000000..d35f4d7c --- /dev/null +++ b/modules/plugins/hydra/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./hydra.nix + ./config.nix + ]; +} diff --git a/modules/plugins/hydra/hydra.nix b/modules/plugins/hydra/hydra.nix new file mode 100644 index 00000000..7b67d66b --- /dev/null +++ b/modules/plugins/hydra/hydra.nix @@ -0,0 +1,8 @@ +{lib, ...}: let + #inherit (lib) types; + inherit (lib.options) mkEnableOption; +in { + options.vim.hydra = { + enable = mkEnableOption "Creating custom submodes and menus [nvimtools/hydra.nvim]"; + }; +} diff --git a/modules/plugins/utility/default.nix b/modules/plugins/utility/default.nix index 65ef8680..95e97588 100644 --- a/modules/plugins/utility/default.nix +++ b/modules/plugins/utility/default.nix @@ -8,6 +8,7 @@ ./icon-picker ./images ./motion + ./multicursors ./new-file-template ./outline ./preview diff --git a/modules/plugins/utility/multicursors/config.nix b/modules/plugins/utility/multicursors/config.nix new file mode 100644 index 00000000..3a2c8d7e --- /dev/null +++ b/modules/plugins/utility/multicursors/config.nix @@ -0,0 +1,68 @@ +{ + options, + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.binds) mkKeymap; + inherit (lib.nvim.binds) addDescriptionsToMappings; # mkSetLuaBinding; + cfg = config.vim.utility.multicursors; + mappingDefinitions = options.vim.utility.multicursors.mappings; + mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = ["hydra-nvim"]; + lazy.plugins.multicursors-nvim = { + package = "multicursors-nvim"; + setupModule = "multicursors"; + #inherit (cfg) setupOpts; + setupOpts = { + DEBUG_MODE = true; + create_commands = true; + updatetime = 50; + nowait = true; + mode_keys = { + append = "a"; + change = "c"; + extend = "e"; + insert = "i"; + }; + hint_config = { + float_opts = { + border = "none"; + }; + position = "bottom"; + }; + generate_hints = { + normal = true; + insert = true; + extend = true; + config = { + column_count = null; + max_hint_length = 25; + }; + }; + }; + + event = ["DeferredUIEnter"]; + cmd = ["MCstart" "MCvisual" "MCclear" "MCpattern" "MCvisualPattern" "MCunderCursor"]; + keys = [ + { + mode = ["v" "n"]; + key = "mcs"; + action = ":MCstart"; + desc = "Create a selection for selected text or word under the cursor [multicursors.nvim]"; + } + { + mode = ["v" "n"]; + key = "mcp"; + action = ":MCpattern"; + desc = "Create a selection for pattern entered [multicursors.nvim]"; + } + ]; + }; + }; + }; +} diff --git a/modules/plugins/utility/multicursors/default.nix b/modules/plugins/utility/multicursors/default.nix new file mode 100644 index 00000000..a1ddac8e --- /dev/null +++ b/modules/plugins/utility/multicursors/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./multicursors.nix + ./config.nix + ]; +} diff --git a/modules/plugins/utility/multicursors/multicursors.nix b/modules/plugins/utility/multicursors/multicursors.nix new file mode 100644 index 00000000..dbd01ce5 --- /dev/null +++ b/modules/plugins/utility/multicursors/multicursors.nix @@ -0,0 +1,17 @@ +{lib, ...}: let + inherit (lib.types) bool int str; + inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; +in { + options.vim.utility.multicursors = { + enable = mkEnableOption "multicursors.nvim plugin (vscode like multiple cursors)"; + + setupOpts = mkPluginSetupOption "multicursors" { + DEBUG_MODE = mkOption { + type = bool; + default = false; + }; + }; + }; +} diff --git a/modules/plugins/utility/multicursors/multicursors.nix.bak b/modules/plugins/utility/multicursors/multicursors.nix.bak new file mode 100644 index 00000000..fcff1639 --- /dev/null +++ b/modules/plugins/utility/multicursors/multicursors.nix.bak @@ -0,0 +1,120 @@ +{lib, ...}: let + inherit (lib.types) bool int str; + inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; + hintConfig = { + float_opts = { + border = mkOption { + type = lib.types.str; + default = "none"; + example = "rounded"; + description = "The border style for the hint window"; + }; + }; + position = mkOption { + default = "bottom"; + type = lib.types.str; + description = "The position of the hint window"; + example = "bottom"; + }; + }; + generateHints = { + normal = mkOption { + type = bool; + default = true; + }; + insert = mkOption { + type = bool; + default = true; + }; + extend = mkOption { + type = bool; + default = true; + }; + config = mkOption { + type = lib.types.attrsOf lib.types.str; + default = { + column_count = "nil"; + max_hint_length = "25"; + }; + }; + }; +in { + options.vim.utility.multicursors = { + enable = mkEnableOption "multicursors.nvim plugin (vscode like multiple cursors)"; + #mappings = { + # mcStart = mkOption { + # type = lib.types.nullOr str; + # description = "Create a selection for selected text or word under the cursor [multicursors.nvim]"; + # default = "ms"; + #}; + #mcStart = mkMappingOption "Create a selection for selected text or word under the cursor [multicursors.nvim]" "ms"; + #}; + setupOpts = mkPluginSetupOption "multicursors" { + DEBUG_MODE = mkOption { + type = bool; + default = false; + }; + create_commands = mkOption { + type = bool; + default = true; + description = "Create Multicursor user commands"; + }; + updatetime = mkOption { + type = int; + default = 50; + description = "The time in milliseconds to wait before updating the cursor in insert mode"; + }; + nowait = mkOption { + type = bool; + default = true; + }; + mode_keys = mkOption { + type = lib.types.attrsOf str; + description = "The keys to use for each mode"; + default = { + insert = "i"; + append = "a"; + change = "c"; + extend = "e"; + }; + }; + normal_keys = mkOption { + type = lib.types.str; + default = "normal_keys"; + }; + insert_keys = mkOption { + type = lib.types.str; + default = "insert_keys"; + }; + extend_keys = mkOption { + type = lib.types.str; + default = "extend_keys"; + }; + hint_config = mkOption { + type = lib.types.submodule hintConfig; + description = "The configuration for the hint window"; + default = { + float_opts = { + border = "none"; + }; + position = "bottom"; + }; + }; + generate_hints = mkOption { + type = lib.types.submodule generateHints; + description = "The configuration for generating hints"; + default = { + normal = true; + insert = true; + extend = true; + config = { + column_count = null; + max_hint_length = 25; + }; + }; + }; + }; + }; +}