diff --git a/docs/release-notes/rl-0.6.md b/docs/release-notes/rl-0.6.md index 01fbe62f5..9f5661459 100644 --- a/docs/release-notes/rl-0.6.md +++ b/docs/release-notes/rl-0.6.md @@ -52,3 +52,4 @@ Release notes for release 0.6 [frothymarrow](https://github.com/frothymarrow) - Added option `vim.luaPackages` to wrap neovim with extra Lua packages. +- `which-key.nvim` categories can now be customized through [vim.binds.which-key.register](vim.binds.which-key.register). diff --git a/modules/utility/binds/which-key/config.nix b/modules/utility/binds/which-key/config.nix index 6e2a83c43..238d88883 100644 --- a/modules/utility/binds/which-key/config.nix +++ b/modules/utility/binds/which-key/config.nix @@ -3,14 +3,17 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.binds.whichKey; in { config = mkIf (cfg.enable) { vim.startPlugins = ["which-key"]; - vim.luaConfigRC.whichkey = nvim.dag.entryAnywhere '' + vim.luaConfigRC.whichkey = entryAnywhere '' local wk = require("which-key") wk.setup ({ key_labels = { @@ -20,108 +23,14 @@ in { [""] = "TAB", }, - ${lib.optionalString (config.vim.ui.borders.plugins.which-key.enable) '' + ${optionalString (config.vim.ui.borders.plugins.which-key.enable) '' window = { border = "${config.vim.ui.borders.plugins.which-key.style}", }, ''} }) - wk.register({ - ${ - if config.vim.tabline.nvimBufferline.enable - then '' - -- Buffer - ["b"] = { name = "+Buffer" }, - ["bm"] = { name = "BufferLineMove" }, - ["bs"] = { name = "BufferLineSort" }, - ["bsi"] = { name = "BufferLineSortById" }, - '' - else "" - } - - ${ - if config.vim.telescope.enable - then '' - ["f"] = { name = "+Telescope" }, - -- Telescope - ["fl"] = { name = "Telescope LSP" }, - ["fm"] = { name = "Cellular Automaton" }, -- TODO: mvoe this to its own parent group - ["fv"] = { name = "Telescope Git" }, - ["fvc"] = { name = "Commits" }, - '' - else "" - } - - ${ - if config.vim.lsp.trouble.enable - then '' - -- Trouble - ["lw"] = { name = "Workspace" }, - ["x"] = { name = "+Trouble" }, -- TODO: move all trouble binds to the same parent group - ["l"] = { name = "+Trouble" }, - '' - else "" - } - - ${ - if config.vim.lsp.nvimCodeActionMenu.enable - then '' - -- Parent Groups - ["c"] = { name = "+CodeAction" }, - '' - else "" - } - - ${ - if config.vim.minimap.codewindow.enable || config.vim.minimap.minimap-vim.enable - then '' - -- Minimap - ["m"] = { name = "+Minimap" }, -- TODO: remap both minimap plugins' keys to be the same - '' - else "" - } - - ${ - if config.vim.notes.mind-nvim.enable || config.vim.notes.obsidian.enable || config.vim.notes.orgmode.enable - then '' - -- Notes - ["o"] = { name = "+Notes" }, - -- TODO: options for other note taking plugins and their individual binds - -- TODO: move all note-taker binds under leader + o - '' - else "" - } - - ${ - # TODO: This probably will need to be reworked for custom-keybinds - if config.vim.filetree.nvimTree.enable - then '' - -- NvimTree - ["t"] = { name = "+NvimTree" }, - '' - else "" - } - - ${ - if config.vim.git.gitsigns.enable - then '' - -- Git - ["g"] = { name = "+Gitsigns" }, - '' - else "" - } - - ${ - if config.vim.utility.preview.glow.enable - then '' - -- Markdown - ["pm"] = { name = "+Preview Markdown" }, - '' - else "" - } - - }) + wk.register(${toLuaObject cfg.register}) ''; }; } diff --git a/modules/utility/binds/which-key/which-key.nix b/modules/utility/binds/which-key/which-key.nix index ceba7de9e..87b558202 100644 --- a/modules/utility/binds/which-key/which-key.nix +++ b/modules/utility/binds/which-key/which-key.nix @@ -1,7 +1,121 @@ -{lib, ...}: let - inherit (lib) mkEnableOption; +{ + config, + lib, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.lists) optionals; + inherit (lib.types) submodule listOf str; in { options.vim.binds.whichKey = { enable = mkEnableOption "which-key keybind helper menu"; + + register = mkOption { + description = "Register label for which-key keybind helper menu"; + type = listOf (submodule { + options = { + keybind = mkOption { + type = str; + description = "Keybind to register"; + }; + label = mkOption { + type = str; + description = "Label for keybind"; + }; + }; + }); + default = + optionals config.vim.tabline.nvimBufferline.enable [ + { + keybind = "b"; + label = "+Buffer"; + } + { + keybind = "bm"; + label = "BufferLineMove"; + } + { + keybind = "bs"; + label = "BufferLineSort"; + } + { + keybind = "bsi"; + label = "BufferLineSortById"; + } + ] + ++ optionals config.vim.telescope.enable [ + { + keybind = "f"; + label = "+Telescope"; + } + { + keybind = "fl"; + label = "Telescope LSP"; + } + { + keybind = "fm"; + label = "Cellular Automaton"; + } + { + keybind = "fv"; + label = "Telescope Git"; + } + { + keybind = "fvc"; + label = "Commits"; + } + ] + ++ optionals config.vim.lsp.trouble.enable [ + { + keybind = "lw"; + label = "Workspace"; + } + { + keybind = "x"; + label = "+Trouble"; + } + { + keybind = "l"; + label = "Trouble"; + } + ] + ++ optionals config.vim.lsp.nvimCodeActionMenu.enable [ + { + keybind = "c"; + label = "+CodeAction"; + } + ] + ++ optionals (config.vim.minimap.codewindow.enable || config.vim.minimap.minimap-vim.enable) [ + { + keybind = "m"; + label = "+Minimap"; + } + ] + ++ optionals (config.vim.notes.mind-nvim.enable || config.vim.notes.obsidian.enable || config.vim.notes.orgmode.enable) [ + { + keybind = "o"; + label = "+Notes"; + } + ] + ++ optionals config.vim.filetree.nvimTree.enable [ + { + keybind = "t"; + label = "+NvimTree"; + } + ] + ++ optionals config.vim.git.gitsigns.enable [ + { + keybind = "g"; + label = "+Gitsigns"; + } + ] + ++ optionals config.vim.utility.preview.glow.enable [ + { + keybind = "pm"; + label = "+Preview Markdown"; + } + ]; + apply = map (x: {${x.keybind} = {name = x.label;};}); + }; }; }