keymaps: fix unable to set noremap = false

Currently setting `vim.keymaps.*.noremap = false` has no effect.
Given that noremap is set by default, the only way to undo it is
to use `remap = true`. This commit adds `remap` as an internal option,
and derives its final value as the inverse of noremap.
This way, setting `noremap` to `false` now behaves as expected.

See https://neovim.io/doc/user/lua-guide.html#_creating-mappings
This commit is contained in:
pax 2026-02-01 15:26:12 -08:00
commit e9d59f47e8
3 changed files with 16 additions and 4 deletions

View file

@ -178,4 +178,8 @@ https://github.com/gorbit99/codewindow.nvim
- Add [codewindow.nvim] plugin in `vim.assistant.codewindow` with `enable` and
`setupOpts`
[irobot](https://github.com/irobot):
- Add `remap` option to `vim.keymaps`
<!-- vim: set textwidth=80: -->

View file

@ -1,6 +1,6 @@
{lib, ...}: let
inherit (lib.options) mkOption literalMD;
inherit (lib.types) either str listOf attrsOf nullOr submodule;
inherit (lib.types) either str listOf attrsOf nullOr submodule bool;
inherit (lib.nvim.config) mkBool;
mapConfigOptions = {
@ -25,6 +25,12 @@
expr = mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
unique = mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
remap = mkOption {
default = false;
type = bool;
internal = true;
description = "'noremap' is on by default. This option is used internally when noremap is set to false.";
};
};
mapType = submodule {

View file

@ -37,9 +37,11 @@ in {
then mkLuaInline keymap.action
else keymap.action;
getOpts = keymap: {
getOpts = keymap:
{
inherit (keymap) desc silent nowait script expr unique noremap;
};
}
// {remap = !keymap.noremap;};
toLuaKeymap = bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject bind.key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";