diff --git a/plugins/bufferlines/barbar.nix b/plugins/bufferlines/barbar.nix index 99b0659c..f23ddbcb 100644 --- a/plugins/bufferlines/barbar.nix +++ b/plugins/bufferlines/barbar.nix @@ -57,7 +57,7 @@ with lib; let } // bufferOptions; - keymaps = { + keymapsActions = { previous = "Previous"; next = "Next"; movePrevious = "MovePrevious"; @@ -227,7 +227,7 @@ in { optionName: funcName: helpers.mkNullOrOption types.str "Keymap for function Buffer${funcName}" ) - keymaps + keymapsActions ); }; @@ -326,20 +326,25 @@ in { } // cfg.extraOptions; - userKeymapsList = - mapAttrsToList + keymaps = + flatten ( - optionName: funcName: let - key = cfg.keymaps.${optionName}; - in - mkIf (key != null) { - ${key} = { + mapAttrsToList + ( + optionName: funcName: let + key = cfg.keymaps.${optionName}; + in + optional + (key != null) + { + mode = "n"; + inherit key; action = "Buffer${funcName}"; - inherit (cfg.keymaps) silent; - }; - } - ) - keymaps; + options.silent = cfg.keymaps.silent; + } + ) + keymapsActions + ); in mkIf cfg.enable { extraPlugins = with pkgs.vimPlugins; [ @@ -347,7 +352,7 @@ in { nvim-web-devicons ]; - maps.normal = mkMerge userKeymapsList; + inherit keymaps; extraConfigLua = '' require('barbar').setup(${helpers.toLuaObject setupOptions}) diff --git a/plugins/languages/julia/julia-cell.nix b/plugins/languages/julia/julia-cell.nix index 2daa700e..bb714d7d 100644 --- a/plugins/languages/julia/julia-cell.nix +++ b/plugins/languages/julia/julia-cell.nix @@ -93,19 +93,19 @@ in // cfg.extraConfig ); - maps.normal = mkMerge ( + keymaps = flatten ( mapAttrsToList ( name: value: let key = cfg.keymaps.${name}; in - if key == null - then {} - else { - ${key} = { - action = ":JuliaCell${value.cmd}"; - inherit (cfg.keymaps) silent; - }; + optional + (key != null) + { + mode = "n"; + inherit key; + action = ":JuliaCell${value.cmd}"; + options.silent = cfg.keymaps.silent; } ) mappings diff --git a/plugins/languages/typst/typst-vim.nix b/plugins/languages/typst/typst-vim.nix index 7c15b84f..b7eae9a3 100644 --- a/plugins/languages/typst/typst-vim.nix +++ b/plugins/languages/typst/typst-vim.nix @@ -34,9 +34,20 @@ in { # Add the typst compiler to nixvim packages extraPackages = with pkgs; [typst]; - maps.normal = with cfg.keymaps; - helpers.mkModeMaps {inherit silent;} { - ${watch} = ":TypstWatch"; - }; + keymaps = with cfg.keymaps; + helpers.mkKeymaps + { + mode = "n"; + options.silent = silent; + } + ( + optional + (watch != null) + { + # mode = "n"; + key = watch; + action = ":TypstWatch"; + } + ); }; } diff --git a/plugins/lsp/default.nix b/plugins/lsp/default.nix index b1c38e02..29ebbad7 100644 --- a/plugins/lsp/default.nix +++ b/plugins/lsp/default.nix @@ -110,30 +110,35 @@ in { mkIf cfg.enable { extraPlugins = [pkgs.vimPlugins.nvim-lspconfig]; - maps.normal = let + keymaps = let mkMaps = prefix: - mapAttrs - (key: action: let - actionStr = - if isString action - then action - else action.action; - actionProps = - if isString action - then {} - else filterAttrs (n: v: n != "action") action; - in - { - inherit (cfg.keymaps) silent; + mapAttrsToList + ( + key: action: let + actionStr = + if isString action + then action + else action.action; + actionProps = + if isString action + then {} + else filterAttrs (n: v: n != "action") action; + in { + mode = "n"; + inherit key; action = prefix + actionStr; lua = true; + + options = + { + inherit (cfg.keymaps) silent; + } + // actionProps; } - // actionProps); + ); in - mkMerge [ - (mkMaps "vim.diagnostic." cfg.keymaps.diagnostic) - (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf) - ]; + (mkMaps "vim.diagnostic." cfg.keymaps.diagnostic) + ++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf); # Enable all LSP servers extraConfigLua = '' diff --git a/plugins/telescope/default.nix b/plugins/telescope/default.nix index 92c7f840..25e74c4c 100644 --- a/plugins/telescope/default.nix +++ b/plugins/telescope/default.nix @@ -83,24 +83,31 @@ in { let $BAT_THEME = '${cfg.highlightTheme}' ''; - maps.normal = - mapAttrs - (key: action: let - actionStr = - if isString action - then action - else action.action; - actionProps = - if isString action - then {} - else filterAttrs (n: v: n != "action") action; - in - { - silent = cfg.keymapsSilent; + keymaps = + mapAttrsToList + ( + key: action: let + actionStr = + if isString action + then action + else action.action; + actionProps = + if isString action + then {} + else filterAttrs (n: v: n != "action") action; + in { + mode = "n"; + inherit key; action = "require('telescope.builtin').${actionStr}"; lua = true; + + options = + { + silent = cfg.keymapsSilent; + } + // actionProps; } - // actionProps) + ) cfg.keymaps; extraConfigLua = let diff --git a/plugins/utils/auto-save.nix b/plugins/utils/auto-save.nix index d420c2fa..27a72ff0 100644 --- a/plugins/utils/auto-save.nix +++ b/plugins/utils/auto-save.nix @@ -142,16 +142,14 @@ in { require('auto-save').setup(${helpers.toLuaObject options}) ''; - maps.normal = with cfg.keymaps; let - inherit (cfg.keymaps) silent; - in - mkMerge [ - (mkIf (toggle != null) { - ${toggle} = { - action = ":ASToggle"; - inherit silent; - }; - }) - ]; + keymaps = with cfg.keymaps; + optional + (toggle != null) + { + mode = "n"; + key = toggle; + action = ":ASToggle"; + options.silent = cfg.keymaps.silent; + }; }; } diff --git a/plugins/utils/coverage.nix b/plugins/utils/coverage.nix index 37289761..88c21d31 100644 --- a/plugins/utils/coverage.nix +++ b/plugins/utils/coverage.nix @@ -299,21 +299,24 @@ in { require("coverage").setup(${helpers.toLuaObject setupOptions}) ''; - maps.normal = mkMerge ( - mapAttrsToList + keymaps = + flatten ( - optionName: properties: let - key = cfg.keymaps.${optionName}; - in - mkIf (key != null) - { - ${key} = { + mapAttrsToList + ( + optionName: properties: let + key = cfg.keymaps.${optionName}; + in + optional + (key != null) + { + mode = "n"; + inherit key; action = ":Coverage${properties.command}"; - silent = cfg.keymapsSilent; - }; - } - ) - keymapsDef - ); + options.silent = cfg.keymapsSilent; + } + ) + keymapsDef + ); }; } diff --git a/plugins/utils/harpoon.nix b/plugins/utils/harpoon.nix index 6ffb8a56..fb320dfb 100644 --- a/plugins/utils/harpoon.nix +++ b/plugins/utils/harpoon.nix @@ -187,22 +187,20 @@ in { require('harpoon').setup(${helpers.toLuaObject options}) ''; - maps.normal = let - silent = cfg.keymapsSilent; + keymaps = let km = cfg.keymaps; - simpleMappings = mkMerge ( + simpleMappings = flatten ( mapAttrsToList ( optionName: luaFunc: let key = km.${optionName}; in - mkIf (key != null) { - ${key} = { - action = luaFunc; - lua = true; - inherit silent; - }; + optional + (key != null) + { + inherit key; + action = luaFunc; } ) { @@ -217,38 +215,44 @@ in { mkNavMappings = name: genLuaFunc: let mappingsAttrs = km.${name}; in - mkIf - (mappingsAttrs != null) + flatten ( - mapAttrs' - (id: key: { - name = key; - value = { + optionals + (mappingsAttrs != null) + ( + mapAttrsToList + (id: key: { + inherit key; action = genLuaFunc id; - lua = true; - inherit silent; - }; - }) - mappingsAttrs + }) + mappingsAttrs + ) ); - in - mkMerge [ + + allMappings = simpleMappings - ( + ++ ( mkNavMappings "navFile" (id: "function() require('harpoon.ui').nav_file(${id}) end") ) - ( + ++ ( mkNavMappings "gotoTerminal" (id: "function() require('harpoon.term').gotoTerminal(${id}) end") ) - ( + ++ ( mkNavMappings "tmuxGotoTerminal" (id: "function() require('harpoon.tmux').gotoTerminal(${id}) end") - ) - ]; + ); + in + helpers.mkKeymaps + { + mode = "n"; + lua = true; + options.silent = cfg.keymapsSilent; + } + allMappings; }; } diff --git a/plugins/utils/intellitab.nix b/plugins/utils/intellitab.nix index 9adb2818..00e9d825 100644 --- a/plugins/utils/intellitab.nix +++ b/plugins/utils/intellitab.nix @@ -19,7 +19,14 @@ in { config = mkIf cfg.enable { extraPlugins = [cfg.package]; - maps.insert."" = "lua require([[intellitab]]).indent()"; + keymaps = [ + { + mode = "i"; + key = ""; + action = "require('intellitab').indent"; + lua = true; + } + ]; plugins.treesitter = { indent = true; }; diff --git a/plugins/utils/neogen.nix b/plugins/utils/neogen.nix index ba106e85..9a59ff00 100644 --- a/plugins/utils/neogen.nix +++ b/plugins/utils/neogen.nix @@ -181,21 +181,23 @@ in { require("neogen").setup(${helpers.toLuaObject setupOptions}) ''; - maps.normal = mkMerge ( - mapAttrsToList + keymaps = + flatten ( - optionName: properties: let - key = cfg.keymaps.${optionName}; - in - mkIf (key != null) - { - ${key} = { + mapAttrsToList + ( + optionName: properties: let + key = cfg.keymaps.${optionName}; + in + optional (key != null) + { + mode = "n"; + inherit key; action = ":Neogen ${properties.command}"; - silent = cfg.keymapsSilent; - }; - } - ) - keymapDef - ); + options.silent = cfg.keymapsSilent; + } + ) + keymapDef + ); }; } diff --git a/plugins/utils/nvim-osc52.nix b/plugins/utils/nvim-osc52.nix index c7bf9e95..93d1e9cf 100644 --- a/plugins/utils/nvim-osc52.nix +++ b/plugins/utils/nvim-osc52.nix @@ -19,6 +19,7 @@ in keymaps = { enable = mkEnableOption "keymaps for copying using OSC52"; + silent = mkOption { type = types.bool; description = "Wether nvim-osc52 keymaps should be silent"; @@ -55,28 +56,36 @@ in mkIf cfg.enable { extraPlugins = [cfg.package]; - maps = mkIf cfg.keymaps.enable { - normal = { - "${cfg.keymaps.copy}" = { + keymaps = with cfg.keymaps; + mkIf enable + [ + { + mode = "n"; + key = copy; action = "require('osc52').copy_operator"; - expr = true; lua = true; - inherit (cfg.keymaps) silent; - }; - "${cfg.keymaps.copyLine}" = { - action = "${cfg.keymaps.copy}_"; - remap = true; - inherit (cfg.keymaps) silent; - }; - }; - visual = { - "${cfg.keymaps.copyVisual}" = { + options = { + expr = true; + inherit silent; + }; + } + { + mode = "n"; + key = copyLine; + action = "${copy}_"; + options = { + remap = true; + inherit silent; + }; + } + { + mode = "v"; + key = copyVisual; action = "require('osc52').copy_visual"; lua = true; - inherit (cfg.keymaps) silent; - }; - }; - }; + options.silent = silent; + } + ]; extraConfigLua = '' require('osc52').setup(${helpers.toLuaObject setupOptions}) diff --git a/plugins/utils/quickmath.nix b/plugins/utils/quickmath.nix index 6fde8568..570a7f07 100644 --- a/plugins/utils/quickmath.nix +++ b/plugins/utils/quickmath.nix @@ -27,11 +27,13 @@ in { config = mkIf cfg.enable { extraPlugins = [cfg.package]; - maps.normal = mkIf (cfg.keymap.key != null) { - ${cfg.keymap.key} = { + keymaps = with cfg.keymap; + optional (key != null) + { + mode = "n"; + inherit key; action = ":Quickmath"; - inherit (cfg.keymap) silent; + options.silent = cfg.keymap.silent; }; - }; }; } diff --git a/plugins/utils/spider.nix b/plugins/utils/spider.nix index 8bb4b401..cc3525dc 100644 --- a/plugins/utils/spider.nix +++ b/plugins/utils/spider.nix @@ -52,25 +52,25 @@ in { // cfg.extraOptions; mappings = - mapAttrs' - (motion: key: { - name = key; - value = { + mapAttrsToList + ( + motion: key: { + mode = ["n" "o" "x"]; + inherit key; action = "function() require('spider').motion('${motion}') end"; lua = true; - inherit (cfg.keymaps) silent; - desc = "Spider-${motion}"; - }; - }) + options = { + inherit (cfg.keymaps) silent; + desc = "Spider-${motion}"; + }; + } + ) cfg.keymaps.motions; in mkIf cfg.enable { extraPlugins = [cfg.package]; - maps = - genAttrs - ["normal" "operator" "visualOnly"] - (mode: mappings); + keymaps = mappings; extraConfigLua = '' require("${pluginName}").setup(${helpers.toLuaObject setupOptions}) diff --git a/plugins/utils/todo-comments.nix b/plugins/utils/todo-comments.nix index 1c0f75eb..eb06e2e8 100644 --- a/plugins/utils/todo-comments.nix +++ b/plugins/utils/todo-comments.nix @@ -264,27 +264,24 @@ in { require("todo-comments").setup${helpers.toLuaObject setupOptions} ''; - maps.normal = let - silent = cfg.keymapsSilent; - inherit (cfg) keymaps; - in - mkMerge ( + keymaps = + flatten + ( mapAttrsToList ( optionName: funcName: let - keymap = keymaps.${optionName}; - - inherit (keymap) key; + keymap = cfg.keymaps.${optionName}; cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}"; keywords = optionalString (keymap.keywords != null) " keywords=${keymap.keywords}"; - - action = ":${funcName}${cwd}${keywords}"; in - mkIf (keymap != null) { - ${key} = { - inherit silent action; - }; + optional + (keymap != null) + { + mode = "n"; + inherit (keymap) key; + action = ":${funcName}${cwd}${keywords}"; + options.silent = cfg.keymapsSilent; } ) commands diff --git a/plugins/utils/vim-bbye.nix b/plugins/utils/vim-bbye.nix index 37c41956..f3574c75 100644 --- a/plugins/utils/vim-bbye.nix +++ b/plugins/utils/vim-bbye.nix @@ -33,20 +33,29 @@ in { config = mkIf cfg.enable { extraPlugins = [cfg.package]; - maps.normal = with cfg.keymaps; - (optionalAttrs (bdelete != null) - { - ${bdelete} = { + keymaps = with cfg.keymaps; + helpers.mkKeymaps + { + mode = "n"; + options.silent = cfg.keymapsSilent; + } + ( + ( + optional + (bdelete != null) + { + key = bdelete; action = ":Bdelete"; - silent = cfg.keymapsSilent; - }; - }) - // (optionalAttrs (bwipeout != null) - { - ${bwipeout} = { + } + ) + ++ ( + optional + (bwipeout != null) + { + key = bwipeout; action = ":Bwipeout"; - silent = cfg.keymapsSilent; - }; - }); + } + ) + ); }; } diff --git a/tests/test-sources/example-configurations/issues.nix b/tests/test-sources/example-configurations/issues.nix index 0a561192..15b47c05 100644 --- a/tests/test-sources/example-configurations/issues.nix +++ b/tests/test-sources/example-configurations/issues.nix @@ -140,6 +140,12 @@ }; "71" = { - maps.normal."hb" = "lua require('gitsigns').blame_line{full=true}"; + keymaps = [ + { + mode = "n"; + key = "hb"; + action = "lua require('gitsigns').blame_line{full=true}"; + } + ]; }; } diff --git a/tests/test-sources/modules/keymaps.nix b/tests/test-sources/modules/keymaps.nix index de56ca22..423ca7dd 100644 --- a/tests/test-sources/modules/keymaps.nix +++ b/tests/test-sources/modules/keymaps.nix @@ -38,9 +38,13 @@ { key = ","; action = "echo \"test\""; + } + { mode = ["n" "s"]; - }; - }; + key = ""; + action = "echo \"test\""; + } + ]; }; mkMaps = { diff --git a/tests/test-sources/plugins/utils/which-key.nix b/tests/test-sources/plugins/utils/which-key.nix index f5057f3b..54abfc7f 100644 --- a/tests/test-sources/plugins/utils/which-key.nix +++ b/tests/test-sources/plugins/utils/which-key.nix @@ -87,6 +87,6 @@ }; }; # Simple mapping with only Description - maps.normal."ff".desc = "Test"; + maps.byMode.normal."ff".options.desc = "Test"; }; }