diff --git a/modules/modules.nix b/modules/modules.nix index 654cd5ce..63605805 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -10,7 +10,6 @@ # such as spellchecking, mappings, and the init script (init.vim). neovim = map (p: ./neovim + "/${p}") [ "init" - "mappings" ]; # Individual plugin modules, separated by the type of plugin. diff --git a/modules/neovim/init/default.nix b/modules/neovim/init/default.nix index 641cc0e1..e831fab6 100644 --- a/modules/neovim/init/default.nix +++ b/modules/neovim/init/default.nix @@ -8,6 +8,7 @@ ./filetype.nix ./highlight.nix ./lsp.nix + ./mappings.nix ./spellcheck.nix ./util.nix ]; diff --git a/modules/neovim/mappings/options.nix b/modules/neovim/init/mappings.nix similarity index 73% rename from modules/neovim/mappings/options.nix rename to modules/neovim/init/mappings.nix index de19b54d..0f665101 100644 --- a/modules/neovim/mappings/options.nix +++ b/modules/neovim/init/mappings.nix @@ -1,19 +1,32 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption literalMD; +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkMerge; + inherit (lib.options) mkOption literalMD; inherit (lib.types) either str listOf attrsOf nullOr submodule; + inherit (lib.attrsets) mapAttrsToList; + inherit (lib.lists) flatten; + inherit (lib.trivial) pipe; + inherit (lib.options) mkEnableOption; inherit (lib.nvim.config) mkBool; mapConfigOptions = { desc = mkOption { type = nullOr str; default = null; - description = "A description of this keybind, to be shown in which-key, if you have it enabled."; + description = '' + Description for the keybind, to be shown in which-key, if you have enabled + in the module system. + ''; }; action = mkOption { type = str; description = "The command to execute."; }; + lua = mkBool false '' If true, `action` is considered to be lua code. Thus, it will not be wrapped in `""`. @@ -55,6 +68,22 @@ }); default = {}; }; + + legacyMapModes = { + normal = ["n"]; + insert = ["i"]; + select = ["s"]; + visual = ["v"]; + terminal = ["t"]; + normalVisualOp = ["n" "v" "o"]; + visualOnly = ["n" "x"]; + operator = ["o"]; + insertCommand = ["i" "c"]; + lang = ["l"]; + command = ["c"]; + }; + + cfg = config.vim; in { options.vim = { vendoredKeymaps.enable = @@ -101,4 +130,27 @@ in { command = legacyMapOption "command-line"; }; }; + + config = { + vim.keymaps = mkMerge [ + ( + pipe cfg.maps + [ + (mapAttrsToList ( + oldMode: keybinds: + mapAttrsToList ( + key: bind: + bind + // { + inherit key; + mode = legacyMapModes.${oldMode}; + } + ) + keybinds + )) + flatten + ] + ) + ]; + }; } diff --git a/modules/neovim/mappings/config.nix b/modules/neovim/mappings/config.nix deleted file mode 100644 index a62a6ca2..00000000 --- a/modules/neovim/mappings/config.nix +++ /dev/null @@ -1,49 +0,0 @@ -{ - config, - lib, - ... -}: let - inherit (lib.modules) mkMerge; - inherit (lib.trivial) pipe; - inherit (lib.attrsets) mapAttrsToList; - inherit (lib.lists) flatten; - - legacyMapModes = { - normal = ["n"]; - insert = ["i"]; - select = ["s"]; - visual = ["v"]; - terminal = ["t"]; - normalVisualOp = ["n" "v" "o"]; - visualOnly = ["n" "x"]; - operator = ["o"]; - insertCommand = ["i" "c"]; - lang = ["l"]; - command = ["c"]; - }; - - cfg = config.vim; -in { - config = { - vim.keymaps = mkMerge [ - ( - pipe cfg.maps - [ - (mapAttrsToList ( - oldMode: keybinds: - mapAttrsToList ( - key: bind: - bind - // { - inherit key; - mode = legacyMapModes.${oldMode}; - } - ) - keybinds - )) - flatten - ] - ) - ]; - }; -} diff --git a/modules/neovim/mappings/default.nix b/modules/neovim/mappings/default.nix deleted file mode 100644 index fe9e1b8e..00000000 --- a/modules/neovim/mappings/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./config.nix - ./options.nix - ]; -}