diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 947025bf..21edbddc 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -4,8 +4,6 @@ Release notes for release 0.7 ## Breaking Changes and Migration Guide {#sec-breaking-changes-and-migration-guide-0-7} -### `vim.configRC` removed - In v0.7 we are removing `vim.configRC` in favor of making `vim.luaConfigRC` the top-level DAG, and thereby making the entire configuration Lua based. This change introduces a few breaking changes: @@ -26,28 +24,6 @@ making good use of its extensive Lua API. Additionally, Vimscript is slow and brings unnecessary performance overhead while working with different configuration formats. -### `vim.maps` rewrite - -Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new -`mode` option has mode has been introduced. It can be either a string, or a list -of strings, where a string represents the short-name of the map mode(s), that -the mapping should be set for. See `:help map-modes` for more information. - -For example: - -```nix -vim.maps.normal."m" = { ... }; -``` - -has to be replaced by - -```nix -vim.maps."m" = { - mode = "n"; - ... -}; -``` - ## Changelog {#sec-release-0.7-changelog} [ItsSorae](https://github.com/ItsSorae): @@ -138,8 +114,6 @@ vim.maps."m" = { has been introduced for setting up internal plugins. See the "DAG entries in nvf" manual page for more information. -- Rewrite `vim.maps`, see the breaking changes section above. - [NotAShelf](https://github.com/notashelf): [ts-error-translator.nvim]: https://github.com/dmmulroy/ts-error-translator.nvim diff --git a/lib/binds.nix b/lib/binds.nix index a8fbf5f0..8c9e9a62 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -4,68 +4,69 @@ inherit (lib.types) nullOr str; inherit (lib.attrsets) isAttrs mapAttrs; - mkLuaBinding = mode: key: action: desc: - mkIf (key != null) { - ${key} = { - inherit mode action desc; - lua = true; - silent = true; - }; - }; - - mkExprBinding = mode: key: action: desc: - mkIf (key != null) { - ${key} = { - inherit mode action desc; - lua = true; - silent = true; - expr = true; - }; - }; - - mkBinding = mode: key: action: desc: - mkIf (key != null) { - ${key} = { - inherit mode action desc; - silent = true; - }; - }; - - mkMappingOption = description: default: - mkOption { - type = nullOr str; - inherit default description; - }; - - # Utility function that takes two attrsets: - # { someKey = "some_value" } and - # { someKey = { description = "Some Description"; }; } - # and merges them into - # { someKey = { value = "some_value"; description = "Some Description"; }; } - addDescriptionsToMappings = actualMappings: mappingDefinitions: - mapAttrs (name: value: let - isNested = isAttrs value; - returnedValue = - if isNested - then addDescriptionsToMappings actualMappings.${name} mappingDefinitions.${name} - else { - inherit value; - inherit (mappingDefinitions.${name}) description; + binds = rec { + mkLuaBinding = key: action: desc: + mkIf (key != null) { + "${key}" = { + inherit action desc; + lua = true; + silent = true; }; - in - returnedValue) - actualMappings; + }; - mkSetBinding = mode: binding: action: - mkBinding mode binding.value action binding.description; + mkExprBinding = key: action: desc: + mkIf (key != null) { + "${key}" = { + inherit action desc; + lua = true; + silent = true; + expr = true; + }; + }; - mkSetExprBinding = mode: binding: action: - mkExprBinding mode binding.value action binding.description; + mkBinding = key: action: desc: + mkIf (key != null) { + "${key}" = { + inherit action desc; + silent = true; + }; + }; - mkSetLuaBinding = mode: binding: action: - mkLuaBinding mode binding.value action binding.description; + mkMappingOption = description: default: + mkOption { + type = nullOr str; + inherit default description; + }; - pushDownDefault = attr: mapAttrs (_: mkDefault) attr; -in { - inherit mkLuaBinding mkExprBinding mkBinding mkMappingOption addDescriptionsToMappings mkSetBinding mkSetExprBinding mkSetLuaBinding pushDownDefault; -} + # Utility function that takes two attrsets: + # { someKey = "some_value" } and + # { someKey = { description = "Some Description"; }; } + # and merges them into + # { someKey = { value = "some_value"; description = "Some Description"; }; } + addDescriptionsToMappings = actualMappings: mappingDefinitions: + mapAttrs (name: value: let + isNested = isAttrs value; + returnedValue = + if isNested + then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}" + else { + inherit value; + inherit (mappingDefinitions."${name}") description; + }; + in + returnedValue) + actualMappings; + + mkSetBinding = binding: action: + mkBinding binding.value action binding.description; + + mkSetExprBinding = binding: action: + mkExprBinding binding.value action binding.description; + + mkSetLuaBinding = binding: action: + mkLuaBinding binding.value action binding.description; + + pushDownDefault = attr: mapAttrs (_: mkDefault) attr; + }; +in + binds diff --git a/modules/neovim/mappings/config.nix b/modules/neovim/mappings/config.nix index 365e1242..28ebf081 100644 --- a/modules/neovim/mappings/config.nix +++ b/modules/neovim/mappings/config.nix @@ -8,26 +8,45 @@ cfg = config.vim; in { config = { - vim.maps = mkIf cfg.disableArrows { - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; + vim.maps = { + normal = mkIf cfg.disableArrows { + "" = { + action = ""; + + noremap = false; + }; + "" = { + action = ""; + + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; }; - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; - }; - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; - }; - "" = { - mode = ["n" "i"]; - action = ""; - noremap = false; + + insert = mkIf cfg.disableArrows { + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; }; }; }; diff --git a/modules/neovim/mappings/options.nix b/modules/neovim/mappings/options.nix index dcf9cf4d..3b1f2634 100644 --- a/modules/neovim/mappings/options.nix +++ b/modules/neovim/mappings/options.nix @@ -1,49 +1,96 @@ {lib, ...}: let inherit (lib.options) mkOption; - inherit (lib.types) either str listOf attrsOf nullOr submodule; + inherit (lib.types) bool str attrsOf nullOr submodule; inherit (lib.nvim.config) mkBool; + # Most of the keybindings code is highly inspired by pta2002/nixvim. + # Thank you! + mapConfigOptions = { + silent = + mkBool false + "Whether this mapping should be silent. Equivalent to adding to a map."; - mapType = submodule { - mode = mkOption { - type = either str (listOf str); - description = '' - The short-name of the mode to set the keymapping for. Passing an empty string is the equivalent of `:map`. + nowait = + mkBool false + "Whether to wait for extra input on ambiguous mappings. Equivalent to adding to a map."; + + script = + mkBool false + "Equivalent to adding