From 8b5ef2cf08f39a6881dfee1335d5665a106d67e6 Mon Sep 17 00:00:00 2001 From: alfarel Date: Sat, 14 Mar 2026 20:17:19 -0400 Subject: [PATCH 1/6] wrapper/lib: init with mkMappingOption mkMappingOption wants to read a setting set in config without passing it every time, so it should be defined in config. --- modules/modules.nix | 1 + modules/neovim/mappings/options.nix | 4 +++- modules/wrapper/lib/config.nix | 20 ++++++++++++++++++++ modules/wrapper/lib/default.nix | 6 ++++++ modules/wrapper/lib/options.nix | 11 +++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 modules/wrapper/lib/config.nix create mode 100644 modules/wrapper/lib/default.nix create mode 100644 modules/wrapper/lib/options.nix diff --git a/modules/modules.nix b/modules/modules.nix index 1eca042a..654cd5ce 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -57,6 +57,7 @@ "rc" "warnings" "lazy" + "lib" ]; # Extra modules, such as deprecation warnings diff --git a/modules/neovim/mappings/options.nix b/modules/neovim/mappings/options.nix index 98e04a65..69ff9311 100644 --- a/modules/neovim/mappings/options.nix +++ b/modules/neovim/mappings/options.nix @@ -1,5 +1,5 @@ {lib, ...}: let - inherit (lib.options) mkOption literalMD; + inherit (lib.options) mkEnableOption mkOption literalMD; inherit (lib.types) either str listOf attrsOf nullOr submodule; inherit (lib.nvim.config) mkBool; @@ -57,6 +57,8 @@ }; in { options.vim = { + vendoredKeymaps = mkEnableOption "this project's vendored keymaps by default" // {default = true;}; + keymaps = mkOption { type = listOf mapType; description = "Custom keybindings."; diff --git a/modules/wrapper/lib/config.nix b/modules/wrapper/lib/config.nix new file mode 100644 index 00000000..54daf5d9 --- /dev/null +++ b/modules/wrapper/lib/config.nix @@ -0,0 +1,20 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) nullOr str; +in { + config.vim.lib = { + mkMappingOption = description: default: + mkOption { + type = nullOr str; + default = + if config.vim.vendoredKeymaps + then default + else null; + inherit description; + }; + }; +} diff --git a/modules/wrapper/lib/default.nix b/modules/wrapper/lib/default.nix new file mode 100644 index 00000000..fe9e1b8e --- /dev/null +++ b/modules/wrapper/lib/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./config.nix + ./options.nix + ]; +} diff --git a/modules/wrapper/lib/options.nix b/modules/wrapper/lib/options.nix new file mode 100644 index 00000000..93b13f1a --- /dev/null +++ b/modules/wrapper/lib/options.nix @@ -0,0 +1,11 @@ +{lib, ...}: let + inherit (lib.options) mkOption; + inherit (lib.types) attrsOf raw; +in { + options.vim.lib = mkOption { + # The second type should be one without merge semantics and which allows function values. + type = attrsOf raw; + default = {}; + internal = true; + }; +} From 1cda8228e998d020f17581166753b802f44d8842 Mon Sep 17 00:00:00 2001 From: alfarel Date: Sat, 14 Mar 2026 20:20:58 -0400 Subject: [PATCH 2/6] plugins: use new config-aware mkMappingOption Generated using: - `sd -F "inherit (lib.nvim.binds) mkMappingOption;" "inherit (config.vim.lib) mkMappingOption;" $(find . -type f)` - `sd -F "{lib, ...}: let" "{config, lib, ...}: let" $(find . -type f)` Tweaked manually (placement in inherit list, fixing todo-comments and toggleterm). Ran `nix run nixpkgs#deadnix -- -e` to clean up. Next commit includes unrelated dead code. --- docs/manual/hacking.md | 2 +- modules/plugins/assistant/chatgpt/chatgpt.nix | 8 ++++++-- modules/plugins/assistant/neocodeium/neocodeium.nix | 8 ++++++-- modules/plugins/comments/comment-nvim/comment-nvim.nix | 8 ++++++-- modules/plugins/completion/blink-cmp/blink-cmp.nix | 8 ++++++-- modules/plugins/completion/nvim-cmp/nvim-cmp.nix | 2 +- modules/plugins/debugger/nvim-dap/nvim-dap.nix | 8 ++++++-- modules/plugins/git/git-conflict/git-conflict.nix | 2 +- modules/plugins/git/gitsigns/gitsigns.nix | 2 +- modules/plugins/git/neogit/neogit.nix | 8 ++++++-- modules/plugins/languages/scala.nix | 2 +- modules/plugins/languages/typst.nix | 3 ++- modules/plugins/lsp/module.nix | 8 ++++++-- modules/plugins/lsp/nvim-docs-view/nvim-docs-view.nix | 8 ++++++-- modules/plugins/lsp/otter/otter.nix | 8 ++++++-- modules/plugins/lsp/trouble/trouble.nix | 8 ++++++-- modules/plugins/minimap/codewindow/codewindow.nix | 8 ++++++-- modules/plugins/notes/todo-comments/todo-comments.nix | 3 ++- modules/plugins/runner/run-nvim/run-nvim.nix | 8 ++++++-- .../plugins/tabline/nvim-bufferline/nvim-bufferline.nix | 2 +- modules/plugins/terminal/toggleterm/toggleterm.nix | 3 ++- modules/plugins/utility/ccc/ccc.nix | 8 ++++++-- .../utility/gestures/gesture-nvim/gesture-nvim.nix | 8 ++++++-- modules/plugins/utility/harpoon/harpoon.nix | 8 ++++++-- modules/plugins/utility/motion/hop/hop.nix | 8 ++++++-- .../plugins/utility/outline/aerial-nvim/aerial-nvim.nix | 8 ++++++-- modules/plugins/utility/preview/glow/glow.nix | 8 ++++++-- modules/plugins/utility/smart-splits/smart-splits.nix | 8 ++++++-- modules/plugins/utility/telescope/telescope.nix | 2 +- modules/plugins/utility/yazi-nvim/yazi-nvim.nix | 8 ++++++-- .../visuals/cellular-automaton/cellular-automaton.nix | 8 ++++++-- 31 files changed, 139 insertions(+), 52 deletions(-) diff --git a/docs/manual/hacking.md b/docs/manual/hacking.md index 40f0854e..37430e67 100644 --- a/docs/manual/hacking.md +++ b/docs/manual/hacking.md @@ -768,7 +768,7 @@ usage should look something like this: # pluginDefinition.nix {lib, ...}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.plugin = { enable = mkEnableOption "Enable plugin"; diff --git a/modules/plugins/assistant/chatgpt/chatgpt.nix b/modules/plugins/assistant/chatgpt/chatgpt.nix index 95dde397..2d644b5c 100644 --- a/modules/plugins/assistant/chatgpt/chatgpt.nix +++ b/modules/plugins/assistant/chatgpt/chatgpt.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.assistant.chatgpt = { enable = mkEnableOption "ChatGPT AI assistant. Requires the environment variable OPENAI_API_KEY to be set"; diff --git a/modules/plugins/assistant/neocodeium/neocodeium.nix b/modules/plugins/assistant/neocodeium/neocodeium.nix index d2ce958c..fe3f3388 100644 --- a/modules/plugins/assistant/neocodeium/neocodeium.nix +++ b/modules/plugins/assistant/neocodeium/neocodeium.nix @@ -1,4 +1,8 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.types) nullOr @@ -11,7 +15,7 @@ ; inherit (lib.options) mkOption mkEnableOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.assistant.neocodeium = { enable = mkEnableOption "NeoCodeium AI completion"; diff --git a/modules/plugins/comments/comment-nvim/comment-nvim.nix b/modules/plugins/comments/comment-nvim/comment-nvim.nix index 76fd8131..fcf73baf 100644 --- a/modules/plugins/comments/comment-nvim/comment-nvim.nix +++ b/modules/plugins/comments/comment-nvim/comment-nvim.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.comments.comment-nvim = { enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim"; diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index d0f0328a..b6967dcb 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,9 +1,13 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption mkOption literalMD; inherit (lib.types) bool listOf str either attrsOf submodule enum anything int nullOr; inherit (lib.nvim.types) mkPluginSetupOption luaInline pluginType; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.config) mkBool; + inherit (config.vim.lib) mkMappingOption; keymapType = submodule { freeformType = attrsOf (listOf (either str luaInline)); diff --git a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix index 4391a144..a16da8d3 100644 --- a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix @@ -6,9 +6,9 @@ inherit (lib.options) mkEnableOption mkOption literalMD; inherit (lib.types) str attrsOf nullOr either listOf; inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf pluginType; inherit (lib.nvim.lua) toLuaObject; + inherit (config.vim.lib) mkMappingOption; inherit (builtins) isString; cfg = config.vim.autocomplete.nvim-cmp; diff --git a/modules/plugins/debugger/nvim-dap/nvim-dap.nix b/modules/plugins/debugger/nvim-dap/nvim-dap.nix index ef582091..521823df 100644 --- a/modules/plugins/debugger/nvim-dap/nvim-dap.nix +++ b/modules/plugins/debugger/nvim-dap/nvim-dap.nix @@ -1,8 +1,12 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) bool attrsOf str; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.debugger.nvim-dap = { enable = mkEnableOption "debugging via nvim-dap"; diff --git a/modules/plugins/git/git-conflict/git-conflict.nix b/modules/plugins/git/git-conflict/git-conflict.nix index 44ab79c5..4e5e6216 100644 --- a/modules/plugins/git/git-conflict/git-conflict.nix +++ b/modules/plugins/git/git-conflict/git-conflict.nix @@ -4,8 +4,8 @@ ... }: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.git.git-conflict = { enable = mkEnableOption "git-conflict" // {default = config.vim.git.enable;}; diff --git a/modules/plugins/git/gitsigns/gitsigns.nix b/modules/plugins/git/gitsigns/gitsigns.nix index 9c2375d8..f7e14c27 100644 --- a/modules/plugins/git/gitsigns/gitsigns.nix +++ b/modules/plugins/git/gitsigns/gitsigns.nix @@ -5,8 +5,8 @@ }: let inherit (lib.options) mkEnableOption; inherit (lib.modules) mkRenamedOptionModule; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { imports = [ (mkRenamedOptionModule ["vim" "git" "gitsigns" "codeActions" "vim" "gitsigns" "codeActions"] ["vim" "git" "gitsigns" "codeActions" "enable"]) diff --git a/modules/plugins/git/neogit/neogit.nix b/modules/plugins/git/neogit/neogit.nix index fa988a32..9800269c 100644 --- a/modules/plugins/git/neogit/neogit.nix +++ b/modules/plugins/git/neogit/neogit.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.git.neogit = { enable = mkEnableOption "An Interactive and powerful Git interface [Neogit]"; diff --git a/modules/plugins/languages/scala.nix b/modules/plugins/languages/scala.nix index bcbe43fe..cf47352c 100644 --- a/modules/plugins/languages/scala.nix +++ b/modules/plugins/languages/scala.nix @@ -6,13 +6,13 @@ }: let inherit (lib.generators) mkLuaInline; inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.types) mkGrammarOption luaInline; inherit (lib.options) mkOption mkEnableOption mkPackageOption literalExpression; inherit (lib.strings) optionalString; inherit (lib.types) attrsOf anything bool; + inherit (config.vim.lib) mkMappingOption; listCommandsAction = if config.vim.telescope.enable diff --git a/modules/plugins/languages/typst.nix b/modules/plugins/languages/typst.nix index 2e29f22b..7cada25b 100644 --- a/modules/plugins/languages/typst.nix +++ b/modules/plugins/languages/typst.nix @@ -13,8 +13,9 @@ inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.binds) mkKeymap mkMappingOption; + inherit (lib.nvim.binds) mkKeymap; inherit (lib.generators) mkLuaInline; + inherit (config.vim.lib) mkMappingOption; cfg = config.vim.languages.typst; diff --git a/modules/plugins/lsp/module.nix b/modules/plugins/lsp/module.nix index 6b63d725..0f81d9a4 100644 --- a/modules/plugins/lsp/module.nix +++ b/modules/plugins/lsp/module.nix @@ -1,6 +1,10 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.lsp = { formatOnSave = mkEnableOption "format on save"; diff --git a/modules/plugins/lsp/nvim-docs-view/nvim-docs-view.nix b/modules/plugins/lsp/nvim-docs-view/nvim-docs-view.nix index df571123..bd96ced7 100644 --- a/modules/plugins/lsp/nvim-docs-view/nvim-docs-view.nix +++ b/modules/plugins/lsp/nvim-docs-view/nvim-docs-view.nix @@ -1,9 +1,13 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption mkOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.types) enum int; inherit (lib.modules) mkRenamedOptionModule; + inherit (config.vim.lib) mkMappingOption; in { imports = let renamedSetupOption = oldPath: newPath: diff --git a/modules/plugins/lsp/otter/otter.nix b/modules/plugins/lsp/otter/otter.nix index 2ccc393b..9529eba5 100644 --- a/modules/plugins/lsp/otter/otter.nix +++ b/modules/plugins/lsp/otter/otter.nix @@ -1,8 +1,12 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.types) bool str listOf; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.lsp = { otter-nvim = { diff --git a/modules/plugins/lsp/trouble/trouble.nix b/modules/plugins/lsp/trouble/trouble.nix index 5fa5a3df..fb2ae1be 100644 --- a/modules/plugins/lsp/trouble/trouble.nix +++ b/modules/plugins/lsp/trouble/trouble.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.lsp = { trouble = { diff --git a/modules/plugins/minimap/codewindow/codewindow.nix b/modules/plugins/minimap/codewindow/codewindow.nix index 9ad48c9f..dcadd64d 100644 --- a/modules/plugins/minimap/codewindow/codewindow.nix +++ b/modules/plugins/minimap/codewindow/codewindow.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.minimap.codewindow = { enable = mkEnableOption "codewindow plugin for minimap view"; diff --git a/modules/plugins/notes/todo-comments/todo-comments.nix b/modules/plugins/notes/todo-comments/todo-comments.nix index b5bb76f0..76f92b1b 100644 --- a/modules/plugins/notes/todo-comments/todo-comments.nix +++ b/modules/plugins/notes/todo-comments/todo-comments.nix @@ -1,4 +1,5 @@ { + config, pkgs, lib, ... @@ -6,8 +7,8 @@ inherit (lib.modules) mkRenamedOptionModule; inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) str listOf; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { imports = let renamedSetupOption = oldPath: newPath: diff --git a/modules/plugins/runner/run-nvim/run-nvim.nix b/modules/plugins/runner/run-nvim/run-nvim.nix index dd24e6c3..e0f9fcc3 100644 --- a/modules/plugins/runner/run-nvim/run-nvim.nix +++ b/modules/plugins/runner/run-nvim/run-nvim.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; inherit (lib.nvim.types) mkPluginSetupOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options = { vim.runner.run-nvim = { diff --git a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix index 384899de..4f33ed86 100644 --- a/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/plugins/tabline/nvim-bufferline/nvim-bufferline.nix @@ -6,8 +6,8 @@ inherit (lib.options) mkOption mkEnableOption literalExpression literalMD; inherit (lib.types) enum bool either nullOr str int listOf attrs; inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (config.vim.lib) mkMappingOption; in { options.vim.tabline.nvimBufferline = { enable = mkEnableOption "neovim bufferline"; diff --git a/modules/plugins/terminal/toggleterm/toggleterm.nix b/modules/plugins/terminal/toggleterm/toggleterm.nix index d6c25c1b..3e72954e 100644 --- a/modules/plugins/terminal/toggleterm/toggleterm.nix +++ b/modules/plugins/terminal/toggleterm/toggleterm.nix @@ -1,14 +1,15 @@ { + config, pkgs, lib, ... }: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.types) nullOr str enum bool package either int; inherit (lib.modules) mkRenamedOptionModule; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.generators) mkLuaInline; + inherit (config.vim.lib) mkMappingOption; in { imports = [ (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"]) diff --git a/modules/plugins/utility/ccc/ccc.nix b/modules/plugins/utility/ccc/ccc.nix index 99c169fb..684fde19 100644 --- a/modules/plugins/utility/ccc/ccc.nix +++ b/modules/plugins/utility/ccc/ccc.nix @@ -1,9 +1,13 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) anything attrsOf listOf enum; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.generators) mkLuaInline; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.ccc = { enable = mkEnableOption "ccc color picker for neovim"; diff --git a/modules/plugins/utility/gestures/gesture-nvim/gesture-nvim.nix b/modules/plugins/utility/gestures/gesture-nvim/gesture-nvim.nix index aad51dc8..e878eb5a 100644 --- a/modules/plugins/utility/gestures/gesture-nvim/gesture-nvim.nix +++ b/modules/plugins/utility/gestures/gesture-nvim/gesture-nvim.nix @@ -1,6 +1,10 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.gestures.gesture-nvim = { enable = mkEnableOption "gesture-nvim: mouse gestures"; diff --git a/modules/plugins/utility/harpoon/harpoon.nix b/modules/plugins/utility/harpoon/harpoon.nix index 6f5b8d0a..002eee1f 100644 --- a/modules/plugins/utility/harpoon/harpoon.nix +++ b/modules/plugins/utility/harpoon/harpoon.nix @@ -1,9 +1,13 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) bool; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.generators) mkLuaInline; + inherit (config.vim.lib) mkMappingOption; in { options.vim.navigation.harpoon = { mappings = { diff --git a/modules/plugins/utility/motion/hop/hop.nix b/modules/plugins/utility/motion/hop/hop.nix index 19d0318f..11d16413 100644 --- a/modules/plugins/utility/motion/hop/hop.nix +++ b/modules/plugins/utility/motion/hop/hop.nix @@ -1,6 +1,10 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.motion.hop = { mappings = { diff --git a/modules/plugins/utility/outline/aerial-nvim/aerial-nvim.nix b/modules/plugins/utility/outline/aerial-nvim/aerial-nvim.nix index beede428..8213068a 100644 --- a/modules/plugins/utility/outline/aerial-nvim/aerial-nvim.nix +++ b/modules/plugins/utility/outline/aerial-nvim/aerial-nvim.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption; inherit (lib.nvim.types) mkPluginSetupOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.outline.aerial-nvim = { enable = mkEnableOption "Aerial.nvim"; diff --git a/modules/plugins/utility/preview/glow/glow.nix b/modules/plugins/utility/preview/glow/glow.nix index 69f9f93d..62cc1ee5 100644 --- a/modules/plugins/utility/preview/glow/glow.nix +++ b/modules/plugins/utility/preview/glow/glow.nix @@ -1,7 +1,11 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.modules) mkRenamedOptionModule; inherit (lib.options) mkEnableOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { imports = [ (mkRenamedOptionModule ["vim" "languages" "markdown" "glow" "enable"] ["vim" "utility" "preview" "glow" "enable"]) diff --git a/modules/plugins/utility/smart-splits/smart-splits.nix b/modules/plugins/utility/smart-splits/smart-splits.nix index dd5c55a3..1b8c5512 100644 --- a/modules/plugins/utility/smart-splits/smart-splits.nix +++ b/modules/plugins/utility/smart-splits/smart-splits.nix @@ -1,8 +1,12 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkOption; inherit (lib.types) bool; inherit (lib.nvim.types) mkPluginSetupOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.smart-splits = { enable = mkOption { diff --git a/modules/plugins/utility/telescope/telescope.nix b/modules/plugins/utility/telescope/telescope.nix index 3aa75ca6..960d1ee5 100644 --- a/modules/plugins/utility/telescope/telescope.nix +++ b/modules/plugins/utility/telescope/telescope.nix @@ -6,8 +6,8 @@ }: let inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.types) int str listOf float bool either enum submodule attrsOf anything package; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (config.vim.lib) mkMappingOption; cfg = config.vim.telescope; setupOptions = { diff --git a/modules/plugins/utility/yazi-nvim/yazi-nvim.nix b/modules/plugins/utility/yazi-nvim/yazi-nvim.nix index 9a83a1a8..3f44e48c 100644 --- a/modules/plugins/utility/yazi-nvim/yazi-nvim.nix +++ b/modules/plugins/utility/yazi-nvim/yazi-nvim.nix @@ -1,8 +1,12 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) bool; inherit (lib.nvim.types) mkPluginSetupOption; - inherit (lib.nvim.binds) mkMappingOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.yazi-nvim = { enable = mkEnableOption '' diff --git a/modules/plugins/visuals/cellular-automaton/cellular-automaton.nix b/modules/plugins/visuals/cellular-automaton/cellular-automaton.nix index 6d432e7b..cad3ffdc 100644 --- a/modules/plugins/visuals/cellular-automaton/cellular-automaton.nix +++ b/modules/plugins/visuals/cellular-automaton/cellular-automaton.nix @@ -1,9 +1,13 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.modules) mkRenamedOptionModule; inherit (lib.options) mkOption mkEnableOption; inherit (lib.nvim.types) luaInline; - inherit (lib.nvim.binds) mkMappingOption; inherit (lib.generators) mkLuaInline; + inherit (config.vim.lib) mkMappingOption; in { imports = [ (mkRenamedOptionModule ["vim" "visuals" "cellularAutomaton"] ["vim" "visuals" "cellular-automaton"]) From f040b4a943869b545c303bff60351e6e73903468 Mon Sep 17 00:00:00 2001 From: alfarel Date: Sat, 14 Mar 2026 22:18:05 -0400 Subject: [PATCH 3/6] plugins: better compatability with nullable keybinds Mostly involves filtering keybinds that are null in cases where the keybind is the attrname, and optionalString for manual lua keybind registration. --- modules/plugins/assistant/copilot/config.nix | 10 +-- .../plugins/completion/blink-cmp/config.nix | 88 ++++++++++--------- .../plugins/completion/nvim-cmp/config.nix | 84 ++++++++++-------- modules/plugins/languages/rust.nix | 39 ++++---- modules/plugins/languages/scala.nix | 2 + .../plugins/terminal/toggleterm/config.nix | 4 +- modules/plugins/ui/breadcrumbs/config.nix | 82 +++++++++-------- modules/plugins/utility/surround/surround.nix | 5 +- 8 files changed, 172 insertions(+), 142 deletions(-) diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 39b0d0ff..9d717a9e 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -21,11 +21,11 @@ ''; mkLuaKeymap = mode: key: action: desc: opts: - opts - // { - inherit mode key action desc; - lua = true; - }; + mkIf (key != null) (opts + // { + inherit mode key action desc; + lua = true; + }); in { config = mkIf cfg.enable { vim = { diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 5789c514..7b29b380 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -5,7 +5,7 @@ }: let inherit (lib.modules) mkIf; inherit (lib.strings) optionalString; - inherit (lib.attrsets) optionalAttrs; + inherit (lib.attrsets) mapAttrs' optionalAttrs; inherit (lib.generators) mkLuaInline; inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList; inherit (lib.lists) map optional optionals elem; @@ -98,51 +98,57 @@ in { preset = "luasnip"; }; - keymap = { - ${mappings.complete} = ["show" "fallback"]; - ${mappings.close} = ["hide" "fallback"]; - ${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"]; - ${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"]; - ${mappings.confirm} = ["accept" "fallback"]; + keymap = + mapAttrs' (mapping-name: action: { + name = mappings.${mapping-name}; + value = action; + }) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) { + complete = ["show" "fallback"]; + close = ["hide" "fallback"]; + scrollDocsUp = ["scroll_documentation_up" "fallback"]; + scrollDocsDown = ["scroll_documentation_down" "fallback"]; + confirm = ["accept" "fallback"]; + next = [ + "select_next" + "snippet_forward" + (mkLuaInline + # lua + '' + function(cmp) + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - ${mappings.next} = [ - "select_next" - "snippet_forward" - (mkLuaInline - # lua - '' - function(cmp) - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - - if has_words_before then - return cmp.show() + if has_words_before then + return cmp.show() + end end - end - '') - "fallback" - ]; - ${mappings.previous} = [ - "select_prev" - "snippet_backward" - "fallback" - ]; - }; + '') + "fallback" + ]; + previous = [ + "select_prev" + "snippet_backward" + "fallback" + ]; + }); # cmdline is not enabled by default, we're just providing keymaps in # case the user enables them - cmdline.keymap = { - ${mappings.complete} = ["show" "fallback"]; - ${mappings.close} = ["hide" "fallback"]; - ${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"]; - ${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"]; - # NOTE: mappings.confirm is skipped because our default, would - # lead to accidental triggers of blink.accept instead of executing - # the cmd - - ${mappings.next} = ["select_next" "show" "fallback"]; - ${mappings.previous} = ["select_prev" "fallback"]; - }; + cmdline.keymap = + mapAttrs' (mapping-name: action: { + name = mappings.${mapping-name}; + value = action; + }) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) { + complete = ["show" "fallback"]; + close = ["hide" "fallback"]; + scrollDocsUp = ["scroll_documentation_up" "fallback"]; + scrollDocsDown = ["scroll_documentation_down" "fallback"]; + # NOTE: mappings.confirm is skipped because our default, would + # lead to accidental triggers of blink.accept instead of executing + # the cmd + next = ["select_next" "show" "fallback"]; + previous = ["select_prev" "fallback"]; + }); }; }; }; diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 9cceb0b7..8a0d19b4 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -3,6 +3,7 @@ config, ... }: let + inherit (lib.attrsets) filterAttrs mapAttrs'; inherit (lib.modules) mkIf; inherit (lib.strings) optionalString; inherit (lib.generators) mkLuaInline; @@ -72,48 +73,53 @@ in { formatting.format = cfg.format; # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section - mapping = { - ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; - ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; - ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; - ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; - ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; + mapping = + mapAttrs' (mapping-name: action: { + name = mappings.${mapping-name}; + value = action; + }) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) + { + complete = mkLuaInline "cmp.mapping.complete()"; + close = mkLuaInline "cmp.mapping.abort()"; + scrollDocsUp = mkLuaInline "cmp.mapping.scroll_docs(-4)"; + scrollDocsDown = mkLuaInline "cmp.mapping.scroll_docs(4)"; + confirm = mkLuaInline "cmp.mapping.confirm({ select = true })"; - ${mappings.next} = mkLuaInline '' - cmp.mapping(function(fallback) - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end + next = mkLuaInline '' + cmp.mapping(function(fallback) + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end - if cmp.visible() then - cmp.select_next_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(1) then - luasnip.jump(1) - ''} - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end) - ''; + if cmp.visible() then + cmp.select_next_item() + ${optionalString luasnipEnable '' + elseif luasnip.locally_jumpable(1) then + luasnip.jump(1) + ''} + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end) + ''; - ${mappings.previous} = mkLuaInline '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - ''} - else - fallback() - end - end) - ''; - }; + previous = mkLuaInline '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + ${optionalString luasnipEnable '' + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + ''} + else + fallback() + end + end) + ''; + }); }; }; }; diff --git a/modules/plugins/languages/rust.nix b/modules/plugins/languages/rust.nix index 3a3e4d1f..d5e8699c 100644 --- a/modules/plugins/languages/rust.nix +++ b/modules/plugins/languages/rust.nix @@ -214,24 +214,31 @@ in { on_attach = function(client, bufnr) default_on_attach(client, bufnr) local opts = { noremap=true, silent=true, buffer = bufnr } - vim.keymap.set("n", "rr", ":RustLsp runnables", opts) - vim.keymap.set("n", "rp", ":RustLsp parentModule", opts) - vim.keymap.set("n", "rm", ":RustLsp expandMacro", opts) - vim.keymap.set("n", "rc", ":RustLsp openCargo", opts) - vim.keymap.set("n", "rg", ":RustLsp crateGraph x11", opts) - ${optionalString cfg.dap.enable '' + + ${optionalString config.vim.vendoredKeymaps '' + vim.keymap.set("n", "rr", ":RustLsp runnables", opts) + vim.keymap.set("n", "rp", ":RustLsp parentModule", opts) + vim.keymap.set("n", "rm", ":RustLsp expandMacro", opts) + vim.keymap.set("n", "rc", ":RustLsp openCargo", opts) + vim.keymap.set("n", "rg", ":RustLsp crateGraph x11", opts) + ''} + + ${optionalString (cfg.dap.enable && config.vim.vendoredKeymaps) '' vim.keymap.set("n", "rd", ":RustLsp debuggables", opts) + ''} + + ${optionalString (cfg.dap.enable && config.vim.debugger.nvim-dap.mappings.continue != null) '' vim.keymap.set( - "n", "${config.vim.debugger.nvim-dap.mappings.continue}", - function() - local dap = require("dap") - if dap.status() == "" then - vim.cmd "RustLsp debuggables" - else - dap.continue() - end - end, - opts + "n", "${config.vim.debugger.nvim-dap.mappings.continue}", + function() + local dap = require("dap") + if dap.status() == "" then + vim.cmd "RustLsp debuggables" + else + dap.continue() + end + end, + opts ) ''} end diff --git a/modules/plugins/languages/scala.nix b/modules/plugins/languages/scala.nix index cf47352c..36fa9048 100644 --- a/modules/plugins/languages/scala.nix +++ b/modules/plugins/languages/scala.nix @@ -117,7 +117,9 @@ in { local attach_metals_keymaps = function(client, bufnr) attach_keymaps(client, bufnr) -- from lsp-setup + ${optionalString (cfg.lsp.extraMappings.listCommands != null) '' vim.api.nvim_buf_set_keymap(bufnr, 'n', '${cfg.lsp.extraMappings.listCommands}', 'lua ${listCommandsAction}', {noremap=true, silent=true, desc='Show all Metals commands'}) + ''} end metals_config = require('metals').bare_config() diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index 85cca09f..a93e2b43 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -54,7 +54,9 @@ in { end }) - vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) + ${optionalString (cfg.lazygit.mappings.open != null) '' + vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) + ''} ''; }; }; diff --git a/modules/plugins/ui/breadcrumbs/config.nix b/modules/plugins/ui/breadcrumbs/config.nix index 324501a5..0988d807 100644 --- a/modules/plugins/ui/breadcrumbs/config.nix +++ b/modules/plugins/ui/breadcrumbs/config.nix @@ -3,6 +3,7 @@ lib, ... }: let + inherit (lib.attrsets) filterAttrs mapAttrs'; inherit (lib.strings) optionalString; inherit (lib.modules) mkIf; inherit (lib.lists) optionals; @@ -30,57 +31,62 @@ in { ]; vim.ui.breadcrumbs.navbuddy.setupOpts = { - mappings = { - ${cfg.navbuddy.mappings.close} = mkLuaInline "actions.close()"; - ${cfg.navbuddy.mappings.nextSibling} = mkLuaInline "actions.next_sibling()"; - ${cfg.navbuddy.mappings.previousSibling} = mkLuaInline "actions.previous_sibling()"; - ${cfg.navbuddy.mappings.parent} = mkLuaInline "actions.parent()"; - ${cfg.navbuddy.mappings.children} = mkLuaInline "actions.children()"; - ${cfg.navbuddy.mappings.root} = mkLuaInline "actions.root()"; + mappings = + mapAttrs' (mapping-name: action: { + name = cfg.navbuddy.mappings.${mapping-name}; + value = action; + }) (filterAttrs (mapping-name: _action: cfg.navbuddy.mappings.${mapping-name} != null) + { + close = mkLuaInline "actions.close()"; + nextSibling = mkLuaInline "actions.next_sibling()"; + previousSibling = mkLuaInline "actions.previous_sibling()"; + parent = mkLuaInline "actions.parent()"; + children = mkLuaInline "actions.children()"; + root = mkLuaInline "actions.root()"; - ${cfg.navbuddy.mappings.visualName} = mkLuaInline "actions.visual_name()"; - ${cfg.navbuddy.mappings.visualScope} = mkLuaInline "actions.visual_scope()"; + visualName = mkLuaInline "actions.visual_name()"; + visualScope = mkLuaInline "actions.visual_scope()"; - ${cfg.navbuddy.mappings.yankName} = mkLuaInline "actions.yank_name()"; - ${cfg.navbuddy.mappings.yankScope} = mkLuaInline "actions.yank_scope()"; + yankName = mkLuaInline "actions.yank_name()"; + yankScope = mkLuaInline "actions.yank_scope()"; - ${cfg.navbuddy.mappings.insertName} = mkLuaInline "actions.insert_name()"; - ${cfg.navbuddy.mappings.insertScope} = mkLuaInline "actions.insert_scope()"; + insertName = mkLuaInline "actions.insert_name()"; + insertScope = mkLuaInline "actions.insert_scope()"; - ${cfg.navbuddy.mappings.appendName} = mkLuaInline "actions.append_name()"; - ${cfg.navbuddy.mappings.appendScope} = mkLuaInline "actions.append_scope()"; + appendName = mkLuaInline "actions.append_name()"; + appendScope = mkLuaInline "actions.append_scope()"; - ${cfg.navbuddy.mappings.rename} = mkLuaInline "actions.rename()"; + rename = mkLuaInline "actions.rename()"; - ${cfg.navbuddy.mappings.delete} = mkLuaInline "actions.delete()"; + delete = mkLuaInline "actions.delete()"; - ${cfg.navbuddy.mappings.foldCreate} = mkLuaInline "actions.fold_create()"; - ${cfg.navbuddy.mappings.foldDelete} = mkLuaInline "actions.fold_delete()"; + foldCreate = mkLuaInline "actions.fold_create()"; + foldDelete = mkLuaInline "actions.fold_delete()"; - ${cfg.navbuddy.mappings.comment} = mkLuaInline "actions.comment()"; + comment = mkLuaInline "actions.comment()"; - ${cfg.navbuddy.mappings.select} = mkLuaInline "actions.select()"; + select = mkLuaInline "actions.select()"; - ${cfg.navbuddy.mappings.moveDown} = mkLuaInline "actions.move_down()"; - ${cfg.navbuddy.mappings.moveUp} = mkLuaInline "actions.move_up()"; + moveDown = mkLuaInline "actions.move_down()"; + moveUp = mkLuaInline "actions.move_up()"; - ${cfg.navbuddy.mappings.togglePreview} = mkLuaInline "actions.toggle_preview()"; + togglePreview = mkLuaInline "actions.toggle_preview()"; - ${cfg.navbuddy.mappings.vsplit} = mkLuaInline "actions.vsplit()"; - ${cfg.navbuddy.mappings.hsplit} = mkLuaInline "actions.hsplit()"; + vsplit = mkLuaInline "actions.vsplit()"; + hsplit = mkLuaInline "actions.hsplit()"; - ${cfg.navbuddy.mappings.telescope} = mkLuaInline '' - actions.telescope({ - layout_strategy = "horizontal", - layout_config = { - height = 0.60, - width = 0.75, - prompt_position = "top", - preview_width = 0.50 - }, - })''; - ${cfg.navbuddy.mappings.help} = mkLuaInline "actions.help()"; - }; + telescope = mkLuaInline '' + actions.telescope({ + layout_strategy = "horizontal", + layout_config = { + height = 0.60, + width = 0.75, + prompt_position = "top", + preview_width = 0.50 + }, + })''; + help = mkLuaInline "actions.help()"; + }); }; vim.pluginRC.breadcrumbs = entryAfter ["lspconfig"] '' diff --git a/modules/plugins/utility/surround/surround.nix b/modules/plugins/utility/surround/surround.nix index 2819b6d6..cb067fd9 100644 --- a/modules/plugins/utility/surround/surround.nix +++ b/modules/plugins/utility/surround/surround.nix @@ -3,7 +3,7 @@ config, ... }: let - inherit (lib.options) mkOption; + inherit (lib.options) literalExpression mkOption; inherit (lib.types) bool str; inherit (lib.nvim.types) mkPluginSetupOption; @@ -64,7 +64,8 @@ in { useVendoredKeybindings = mkOption { type = bool; - default = true; + default = config.vim.vendoredKeymaps; + defaultText = literalExpression "config.vim.vendoredKeymaps"; description = '' Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap ''; From 5e1ee37e7f8670b57d502d71f00283258520ae20 Mon Sep 17 00:00:00 2001 From: alfarel Date: Sat, 14 Mar 2026 22:19:58 -0400 Subject: [PATCH 4/6] plugins: use mkMappingOption instead of mkOption where possible --- modules/plugins/assistant/copilot/copilot.nix | 76 ++----- .../supermaven-nvim/supermaven-nvim.nix | 28 +-- .../plugins/filetree/nvimtree/nvimtree.nix | 28 +-- modules/plugins/lsp/module.nix | 80 ++------ .../nvim-session-manager.nix | 34 +--- .../terminal/toggleterm/toggleterm.nix | 8 +- .../plugins/ui/breadcrumbs/breadcrumbs.nix | 190 +++--------------- .../plugins/utility/motion/flash/flash.nix | 40 ++-- modules/plugins/utility/motion/leap/leap.nix | 40 ++-- 9 files changed, 113 insertions(+), 411 deletions(-) diff --git a/modules/plugins/assistant/copilot/copilot.nix b/modules/plugins/assistant/copilot/copilot.nix index 24c4286b..47da0699 100644 --- a/modules/plugins/assistant/copilot/copilot.nix +++ b/modules/plugins/assistant/copilot/copilot.nix @@ -8,6 +8,7 @@ inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) nullOr str enum float; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; cfg = config.vim.assistant.copilot; in { @@ -59,72 +60,19 @@ in { mappings = { panel = { - jumpPrev = mkOption { - type = nullOr str; - default = "[["; - description = "Jump to previous suggestion"; - }; - - jumpNext = mkOption { - type = nullOr str; - default = "]]"; - description = "Jump to next suggestion"; - }; - - accept = mkOption { - type = nullOr str; - default = ""; - description = "Accept suggestion"; - }; - - refresh = mkOption { - type = nullOr str; - default = "gr"; - description = "Refresh suggestions"; - }; - - open = mkOption { - type = nullOr str; - default = ""; - description = "Open suggestions"; - }; + jumpPrev = mkMappingOption "Jump to previous suggestion" "[["; + jumpNext = mkMappingOption "Jump to next suggestion" "]]"; + accept = mkMappingOption "Accept suggestion" ""; + refresh = mkMappingOption "Refresh suggestions" "gr"; + open = mkMappingOption "Open suggestions" ""; }; suggestion = { - accept = mkOption { - type = nullOr str; - default = ""; - description = "Accept suggestion"; - }; - - acceptWord = mkOption { - type = nullOr str; - default = null; - description = "Accept next word"; - }; - - acceptLine = mkOption { - type = nullOr str; - default = null; - description = "Accept next line"; - }; - - prev = mkOption { - type = nullOr str; - default = ""; - description = "Previous suggestion"; - }; - - next = mkOption { - type = nullOr str; - default = ""; - description = "Next suggestion"; - }; - - dismiss = mkOption { - type = nullOr str; - default = ""; - description = "Dismiss suggestion"; - }; + accept = mkMappingOption "Accept suggestion" ""; + acceptWord = mkMappingOption "Accept next word" null; + acceptLine = mkMappingOption "Accept next line" null; + prev = mkMappingOption "Previous suggestion" ""; + next = mkMappingOption "Next suggestion" ""; + dismiss = mkMappingOption "Dismiss suggestion" ""; }; }; }; diff --git a/modules/plugins/assistant/supermaven-nvim/supermaven-nvim.nix b/modules/plugins/assistant/supermaven-nvim/supermaven-nvim.nix index 0d1efd19..35346855 100644 --- a/modules/plugins/assistant/supermaven-nvim/supermaven-nvim.nix +++ b/modules/plugins/assistant/supermaven-nvim/supermaven-nvim.nix @@ -1,4 +1,8 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.types) nullOr @@ -10,30 +14,16 @@ ; inherit (lib.options) mkOption mkEnableOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (config.vim.lib) mkMappingOption; in { options.vim.assistant.supermaven-nvim = { enable = mkEnableOption "Supermaven AI assistant"; setupOpts = mkPluginSetupOption "Supermaven" { keymaps = { - accept_suggestion = mkOption { - type = nullOr str; - default = null; - example = ""; - description = "The key to accept a suggestion"; - }; - clear_suggestion = mkOption { - type = nullOr str; - default = null; - example = ""; - description = "The key to clear a suggestion"; - }; - accept_word = mkOption { - type = nullOr str; - default = null; - example = ""; - description = "The key to accept a word"; - }; + accept_suggestion = mkMappingOption "The key to accept a suggestion" null // {example = "";}; + clear_suggestion = mkMappingOption "The key to clear a suggestion" null // {example = "";}; + accept_word = mkMappingOption "The key to accept a word" null // {example = "";}; }; ignore_file = mkOption { type = nullOr (attrsOf bool); diff --git a/modules/plugins/filetree/nvimtree/nvimtree.nix b/modules/plugins/filetree/nvimtree/nvimtree.nix index c3beb38f..e3d36703 100644 --- a/modules/plugins/filetree/nvimtree/nvimtree.nix +++ b/modules/plugins/filetree/nvimtree/nvimtree.nix @@ -1,13 +1,15 @@ { + config, pkgs, lib, ... }: let inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.generators) mkLuaInline; - inherit (lib.types) nullOr str bool int submodule listOf enum oneOf attrs addCheck; + inherit (lib.types) str bool int submodule listOf enum oneOf attrs addCheck; inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.nvim.config) batchRenameOptions; + inherit (config.vim.lib) mkMappingOption; migrationTable = { disableNetrw = "disable_netrw"; @@ -76,26 +78,10 @@ in { enable = mkEnableOption "filetree via nvim-tree.lua"; mappings = { - toggle = mkOption { - type = nullOr str; - default = "t"; - description = "Toggle NvimTree"; - }; - refresh = mkOption { - type = nullOr str; - default = "tr"; - description = "Refresh NvimTree"; - }; - findFile = mkOption { - type = nullOr str; - default = "tg"; - description = "Find file in NvimTree"; - }; - focus = mkOption { - type = nullOr str; - default = "tf"; - description = "Focus NvimTree"; - }; + toggle = mkMappingOption "Toggle NvimTree" "t"; + refresh = mkMappingOption "Refresh NvimTree" "tr"; + findFile = mkMappingOption "Find file in NvimTree" "tg"; + focus = mkMappingOption "Focus NvimTree" "tf"; }; setupOpts = mkPluginSetupOption "Nvim Tree" { diff --git a/modules/plugins/lsp/module.nix b/modules/plugins/lsp/module.nix index 0f81d9a4..6b8f8640 100644 --- a/modules/plugins/lsp/module.nix +++ b/modules/plugins/lsp/module.nix @@ -14,66 +14,26 @@ in { }; mappings = { - goToDefinition = - mkMappingOption "Go to definition" - "lgd"; - goToDeclaration = - mkMappingOption "Go to declaration" - "lgD"; - goToType = - mkMappingOption "Go to type" - "lgt"; - listImplementations = - mkMappingOption "List implementations" - "lgi"; - listReferences = - mkMappingOption "List references" - "lgr"; - nextDiagnostic = - mkMappingOption "Go to next diagnostic" - "lgn"; - previousDiagnostic = - mkMappingOption "Go to previous diagnostic" - "lgp"; - openDiagnosticFloat = - mkMappingOption "Open diagnostic float" - "le"; - documentHighlight = - mkMappingOption "Document highlight" - "lH"; - listDocumentSymbols = - mkMappingOption "List document symbols" - "lS"; - addWorkspaceFolder = - mkMappingOption "Add workspace folder" - "lwa"; - removeWorkspaceFolder = - mkMappingOption "Remove workspace folder" - "lwr"; - listWorkspaceFolders = - mkMappingOption "List workspace folders" - "lwl"; - listWorkspaceSymbols = - mkMappingOption "List workspace symbols" - "lws"; - hover = - mkMappingOption "Trigger hover" - "lh"; - signatureHelp = - mkMappingOption "Signature help" - "ls"; - renameSymbol = - mkMappingOption "Rename symbol" - "ln"; - codeAction = - mkMappingOption "Code action" - "la"; - format = - mkMappingOption "Format" - "lf"; - toggleFormatOnSave = - mkMappingOption "Toggle format on save" - "ltf"; + goToDefinition = mkMappingOption "Go to definition" "lgd"; + goToDeclaration = mkMappingOption "Go to declaration" "lgD"; + goToType = mkMappingOption "Go to type" "lgt"; + listImplementations = mkMappingOption "List implementations" "lgi"; + listReferences = mkMappingOption "List references" "lgr"; + nextDiagnostic = mkMappingOption "Go to next diagnostic" "lgn"; + previousDiagnostic = mkMappingOption "Go to previous diagnostic" "lgp"; + openDiagnosticFloat = mkMappingOption "Open diagnostic float" "le"; + documentHighlight = mkMappingOption "Document highlight" "lH"; + listDocumentSymbols = mkMappingOption "List document symbols" "lS"; + addWorkspaceFolder = mkMappingOption "Add workspace folder" "lwa"; + removeWorkspaceFolder = mkMappingOption "Remove workspace folder" "lwr"; + listWorkspaceFolders = mkMappingOption "List workspace folders" "lwl"; + listWorkspaceSymbols = mkMappingOption "List workspace symbols" "lws"; + hover = mkMappingOption "Trigger hover" "lh"; + signatureHelp = mkMappingOption "Signature help" "ls"; + renameSymbol = mkMappingOption "Rename symbol" "ln"; + codeAction = mkMappingOption "Code action" "la"; + format = mkMappingOption "Format" "lf"; + toggleFormatOnSave = mkMappingOption "Toggle format on save" "ltf"; }; }; } diff --git a/modules/plugins/session/nvim-session-manager/nvim-session-manager.nix b/modules/plugins/session/nvim-session-manager/nvim-session-manager.nix index 8390d1ce..2dbfb654 100644 --- a/modules/plugins/session/nvim-session-manager/nvim-session-manager.nix +++ b/modules/plugins/session/nvim-session-manager/nvim-session-manager.nix @@ -1,10 +1,15 @@ -{lib, ...}: let +{ + config, + lib, + ... +}: let inherit (lib.options) mkOption mkEnableOption; inherit (lib.modules) mkRenamedOptionModule; inherit (lib.strings) isString; inherit (lib.types) nullOr str bool int enum listOf either; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.types) luaInline mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { imports = let renameSetupOpt = oldPath: newPath: @@ -26,29 +31,10 @@ in { enable = mkEnableOption "nvim-session-manager: manage sessions like folders in VSCode"; mappings = { - loadSession = mkOption { - type = nullOr str; - description = "Load session"; - default = "sl"; - }; - - deleteSession = mkOption { - type = nullOr str; - description = "Delete session"; - default = "sd"; - }; - - saveCurrentSession = mkOption { - type = nullOr str; - description = "Save current session"; - default = "sc"; - }; - - loadLastSession = mkOption { - type = nullOr str; - description = "Load last session"; - default = "slt"; - }; + loadSession = mkMappingOption "Load session" "sl"; + deleteSession = mkMappingOption "Delete session" "sd"; + saveCurrentSession = mkMappingOption "Save current session" "sc"; + loadLastSession = mkMappingOption "Load last session" "slt"; }; usePicker = mkOption { diff --git a/modules/plugins/terminal/toggleterm/toggleterm.nix b/modules/plugins/terminal/toggleterm/toggleterm.nix index 3e72954e..6b443b9e 100644 --- a/modules/plugins/terminal/toggleterm/toggleterm.nix +++ b/modules/plugins/terminal/toggleterm/toggleterm.nix @@ -5,7 +5,7 @@ ... }: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) nullOr str enum bool package either int; + inherit (lib.types) nullOr enum bool package either int; inherit (lib.modules) mkRenamedOptionModule; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.generators) mkLuaInline; @@ -19,11 +19,7 @@ in { options.vim.terminal.toggleterm = { enable = mkEnableOption "toggleterm as a replacement to built-in terminal command"; mappings = { - open = mkOption { - type = nullOr str; - description = "The keymapping to open toggleterm"; - default = ""; - }; + open = mkMappingOption "Open toggleterm" ""; }; setupOpts = mkPluginSetupOption "ToggleTerm" { diff --git a/modules/plugins/ui/breadcrumbs/breadcrumbs.nix b/modules/plugins/ui/breadcrumbs/breadcrumbs.nix index 72351ecc..4769166b 100644 --- a/modules/plugins/ui/breadcrumbs/breadcrumbs.nix +++ b/modules/plugins/ui/breadcrumbs/breadcrumbs.nix @@ -7,6 +7,8 @@ inherit (lib.types) nullOr listOf enum bool str int; inherit (lib.modules) mkRenamedOptionModule; inherit (lib.nvim.types) mkPluginSetupOption borderType; + inherit (config.vim.lib) mkMappingOption; + mkSimpleIconOption = default: mkOption { inherit default; @@ -83,167 +85,33 @@ in { navbuddy = { enable = mkEnableOption "navbuddy LSP helper UI. Enabling this option automatically loads and enables nvim-navic"; mappings = { - close = mkOption { - type = str; - default = ""; - description = "Close and return the cursor to its original location."; - }; - - nextSibling = mkOption { - type = str; - default = "j"; - description = "Navigate to the next sibling node."; - }; - - previousSibling = mkOption { - type = str; - default = "k"; - description = "Navigate to the previous sibling node."; - }; - - parent = mkOption { - type = str; - default = "h"; - description = "Navigate to the parent node."; - }; - - children = mkOption { - type = str; - default = "l"; - description = "Navigate to the child node."; - }; - - root = mkOption { - type = str; - default = "0"; - description = "Navigate to the root node."; - }; - - visualName = mkOption { - type = str; - default = "v"; - description = "Select the name visually."; - }; - - visualScope = mkOption { - type = str; - default = "V"; - description = "Select the scope visually."; - }; - - yankName = mkOption { - type = str; - default = "y"; - description = "Yank the name to system clipboard."; - }; - - yankScope = mkOption { - type = str; - default = "Y"; - description = "Yank the scope to system clipboard."; - }; - - insertName = mkOption { - type = str; - default = "i"; - description = "Insert at the start of name."; - }; - - insertScope = mkOption { - type = str; - default = "I"; - description = "Insert at the start of scope."; - }; - - appendName = mkOption { - type = str; - default = "a"; - description = "Insert at the end of name."; - }; - - appendScope = mkOption { - type = str; - default = "A"; - description = "Insert at the end of scope."; - }; - - rename = mkOption { - type = str; - default = "r"; - description = "Rename the node."; - }; - - delete = mkOption { - type = str; - default = "d"; - description = "Delete the node."; - }; - - foldCreate = mkOption { - type = str; - default = "f"; - description = "Create a new fold of the node."; - }; - - foldDelete = mkOption { - type = str; - default = "F"; - description = "Delete the current fold of the node."; - }; - - comment = mkOption { - type = str; - default = "c"; - description = "Comment the node."; - }; - - select = mkOption { - type = str; - default = ""; - description = "Goto the node."; - }; - - moveDown = mkOption { - type = str; - default = "J"; - description = "Move the node down."; - }; - - moveUp = mkOption { - type = str; - default = "K"; - description = "Move the node up."; - }; - - togglePreview = mkOption { - type = str; - default = "s"; - description = "Toggle the preview."; - }; - - vsplit = mkOption { - type = str; - default = ""; - description = "Open the node in a vertical split."; - }; - - hsplit = mkOption { - type = str; - default = ""; - description = "Open the node in a horizontal split."; - }; - - telescope = mkOption { - type = str; - default = "t"; - description = "Start fuzzy finder at the current level."; - }; - - help = mkOption { - type = str; - default = "g?"; - description = "Open the mappings help window."; - }; + close = mkMappingOption "Close and return the cursor to its original location." ""; + nextSibling = mkMappingOption "Navigate to the next sibling node." "j"; + previousSibling = mkMappingOption "Navigate to the previous sibling node." "k"; + parent = mkMappingOption "Navigate to the parent node." "h"; + children = mkMappingOption "Navigate to the child node." "l"; + root = mkMappingOption "Navigate to the root node." "0"; + visualName = mkMappingOption "Select the name visually." "v"; + visualScope = mkMappingOption "Select the scope visually." "V"; + yankName = mkMappingOption "Yank the name to system clipboard." "y"; + yankScope = mkMappingOption "Yank the scope to system clipboard." "Y"; + insertName = mkMappingOption "Insert at the start of name." "i"; + insertScope = mkMappingOption "Insert at the start of scope." "I"; + appendName = mkMappingOption "Insert at the end of name." "a"; + appendScope = mkMappingOption "Insert at the end of scope." "A"; + rename = mkMappingOption "Rename the node." "r"; + delete = mkMappingOption "Delete the node." "d"; + foldCreate = mkMappingOption "Create a new fold of the node." "f"; + foldDelete = mkMappingOption "Delete the current fold of the node." "F"; + comment = mkMappingOption "Comment the node." "c"; + select = mkMappingOption "Goto the node." ""; + moveDown = mkMappingOption "Move the node down." "J"; + moveUp = mkMappingOption "Move the node up." "K"; + togglePreview = mkMappingOption "Toggle the preview." "s"; + vsplit = mkMappingOption "Open the node in a vertical split." ""; + hsplit = mkMappingOption "Open the node in a horizontal split." ""; + telescope = mkMappingOption "Start fuzzy finder at the current level." "t"; + help = mkMappingOption "Open the mappings help window." "g?"; }; setupOpts = mkPluginSetupOption "navbuddy" { diff --git a/modules/plugins/utility/motion/flash/flash.nix b/modules/plugins/utility/motion/flash/flash.nix index 825b86a0..55672a4d 100644 --- a/modules/plugins/utility/motion/flash/flash.nix +++ b/modules/plugins/utility/motion/flash/flash.nix @@ -1,38 +1,22 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) nullOr str; +{ + config, + lib, + ... +}: let + inherit (lib.options) mkEnableOption; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.motion.flash-nvim = { enable = mkEnableOption "enhanced code navigation with flash.nvim"; setupOpts = mkPluginSetupOption "flash-nvim" {}; mappings = { - jump = mkOption { - type = nullOr str; - default = "s"; - description = "Jump"; - }; - treesitter = mkOption { - type = nullOr str; - default = "S"; - description = "Treesitter"; - }; - remote = mkOption { - type = nullOr str; - default = "r"; - description = "Remote Flash"; - }; - treesitter_search = mkOption { - type = nullOr str; - default = "R"; - description = "Treesitter Search"; - }; - toggle = mkOption { - type = nullOr str; - default = ""; - description = "Toggle Flash Search"; - }; + jump = mkMappingOption "Jump" "s"; + treesitter = mkMappingOption "Treesitter" "S"; + remote = mkMappingOption "Remote Flash" "r"; + treesitter_search = mkMappingOption "Treesitter Search" "R"; + toggle = mkMappingOption "Toggle Flash Search" ""; }; }; } diff --git a/modules/plugins/utility/motion/leap/leap.nix b/modules/plugins/utility/motion/leap/leap.nix index 4e98f208..c443e781 100644 --- a/modules/plugins/utility/motion/leap/leap.nix +++ b/modules/plugins/utility/motion/leap/leap.nix @@ -1,36 +1,20 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) nullOr str; +{ + config, + lib, + ... +}: let + inherit (lib.options) mkEnableOption; + inherit (config.vim.lib) mkMappingOption; in { options.vim.utility.motion.leap = { enable = mkEnableOption "leap.nvim plugin (easy motion)"; mappings = { - leapForwardTo = mkOption { - type = nullOr str; - description = "Leap forward to"; - default = "ss"; - }; - leapBackwardTo = mkOption { - type = nullOr str; - description = "Leap backward to"; - default = "sS"; - }; - leapForwardTill = mkOption { - type = nullOr str; - description = "Leap forward till"; - default = "sx"; - }; - leapBackwardTill = mkOption { - type = nullOr str; - description = "Leap backward till"; - default = "sX"; - }; - leapFromWindow = mkOption { - type = nullOr str; - description = "Leap from window"; - default = "gs"; - }; + leapForwardTo = mkMappingOption "Leap forward to" "ss"; + leapBackwardTo = mkMappingOption "Leap backward to" "sS"; + leapForwardTill = mkMappingOption "Leap forward till" "sx"; + leapBackwardTill = mkMappingOption "Leap backward till" "sX"; + leapFromWindow = mkMappingOption "Leap from window" "gs"; }; }; } From 69379e91f7c3e67cb742635b02bcfa9df03b2d6e Mon Sep 17 00:00:00 2001 From: alfarel Date: Sun, 15 Mar 2026 11:09:25 -0400 Subject: [PATCH 5/6] docs: add `vendoredKeymaps` to release notes --- docs/manual/release-notes/rl-0.9.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 7b784b9a..dcd6e985 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -182,6 +182,7 @@ {command}`:healthcheck` doesn't know that. - Remove [which-key.nvim] `o` `+Notes` description which did not actually correspond to any keybinds. +- Allow disabling nvf's vendored keymaps by toggling `vendoredKeymaps`. [pyrox0](https://github.com/pyrox0): From 3860063606034aefeb427b432016fcdc5e698dc7 Mon Sep 17 00:00:00 2001 From: alfarel Date: Mon, 30 Mar 2026 10:10:02 -0400 Subject: [PATCH 6/6] docs: note `vendoredKeymaps` and ability to disable keymap options --- docs/manual/configuring/keybinds.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/manual/configuring/keybinds.md b/docs/manual/configuring/keybinds.md index 401799c1..7bd4225f 100644 --- a/docs/manual/configuring/keybinds.md +++ b/docs/manual/configuring/keybinds.md @@ -1,8 +1,10 @@ # Custom keymaps {#ch-keymaps} -Some plugin modules provide keymap options for your convenience. If a keymap is -not provided by such module options, you may easily register your own custom -keymaps via {option}`vim.keymaps`. +Some plugin modules provide keymap options for your convenience. These can be +disabled using {option}`vim.vendoredKeymaps`. It is also possible to disable +individual keymaps with options by setting them to `null`. If a keymap is not +provided by a module, you may easily register your own custom keymaps via +{option}`vim.keymaps`. ```nix { @@ -22,7 +24,7 @@ keymaps via {option}`vim.keymaps`. { key = "k"; mode = ["n" "x"]; - + # While `lua` is `true`, `action` is expected to be # a valid Lua expression. lua = true;