Skip to content

fix(config): merge keybindings by name and key instead of name alone - #18870

Merged
kronberger-droid merged 5 commits into
nushell:mainfrom
kronberger-droid:fix/keybinding-merge-shared-names
Aug 21, 2026
Merged

kronberger-droid merged 5 commits into
nushell:mainfrom
kronberger-droid:fix/keybinding-merge-shared-names

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

Since 0.115.0 assigning $env.config.keybindings merges by matching named bindings on name alone, so a named binding silently replaces an earlier one that binds a different key.
Atuin's generated init.nu names both its ctrl-r and up-arrow bindings atuin, thus ctrl-r silently fell back to the built-in history menu (#18848).

The merge now takes the name as the primary key, with the key identity (modifier/keycode/mode, normalised so emacs == [emacs]) deciding between bindings that share one.
An exact name-and-key match is replaced, so re-sourcing is idempotent and event updates land; a named binding with a new key re-keys the entry of that name in place, keeping its position ($env.config.keybindings.0.keycode = ... depends on this); anything else appends, with a one-time warning (nu::shell::shared_keybindings_name) when that fans a name out to a second key.
A claim flag lets atuin's two same-named bindings coexist: the first claims its entry exactly, so the second appends instead of re-keying its sibling.

Assigning = [] now resets the list, which the merge semantics had silently made impossible.

User-facing changes (Release notes)

Fix $env.config.keybindings merging for shared names

Fixed an issue where two keybindings sharing a name on different keys silently dropped one of them (broke atuin's ctrl-r).
Nushell now warns once when keybindings share a name, matches mode spellings like emacs and [emacs] when merging, and $env.config.keybindings = [] clears the list again.

Additional notes

fixes #18848

@github-actions

Copy link
Copy Markdown

Hey, just a bot checking in! You edited files related to the configuration.
If you changed any of the default values or added a new config option, don't forget to update the doc_config.nu which documents the options for our users including the defaults provided by the Rust implementation.
If you didn't make a change here, you can just ignore me.

…e needs

`KeyIdentity` is what makes two bindings the same key: modifier, keycode
and the mode set, lowered and order-normalised, so `emacs` == `[emacs]`
and `[emacs vi_insert]` == `[vi_insert emacs]`. `name_of` lifts the
`Option<Value>` name into a comparable `Option<String>`. Both replace
raw `Value` equality, which missed every alternative spelling.

`ConfigWarning::SharedKeybindingName` reports bindings sharing a name;
hashed by the name list so a new duplicate still warns after an earlier
one was reported once.
@kronberger-droid
kronberger-droid force-pushed the fix/keybinding-merge-shared-names branch from fe55662 to 6df589d Compare August 20, 2026 18:10
@kronberger-droid kronberger-droid changed the title Fix/keybinding merge shared names fix(config): merge keybindings by name and key instead of name alone Aug 20, 2026
…siblings

Since 0.115 a named binding replaced any earlier binding with the same
name, key ignored; atuin's generated config names both its ctrl-r and
up-arrow bindings `atuin`, so ctrl-r silently fell back to the built-in
history menu (nushell#18848).

The merge now takes the name as the primary key and the key identity
(modifier, keycode and the mode set, normalised so `emacs` == `[emacs]`)
to decide between bindings sharing one. Per incoming binding: an exact
name-and-key match is replaced (idempotent re-source, event updates); a
named binding with a new key re-keys the unclaimed entry of that name in
place, keeping its list position, which is what
`$env.config.keybindings.0.keycode = ...` depends on; anything else is
appended, with a one-time warning when that fans a name out to a second
key. The claimed flag is what lets atuin's two same-named bindings
coexist: the first claims its entry exactly, the second starts a new
one instead of re-keying its sibling.

Assigning `= []` resets the list, which the merge semantics had silently
made impossible.

Fixes nushell#18848
@kronberger-droid
kronberger-droid force-pushed the fix/keybinding-merge-shared-names branch from 6df589d to 30ee275 Compare August 20, 2026 18:32
@fdncred
fdncred requested a balanced review from Copilot August 20, 2026 18:55
@fdncred

fdncred commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Looks good to me. Let's see what copilot thinks.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates keybinding merging to preserve same-named bindings on distinct keys while supporting replacement, re-keying, warnings, and list reset.

Changes:

  • Adds normalized key identities and revised merge semantics.
  • Adds shared-name warnings and regression tests.
  • Documents keybinding merging and reset behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
crates/nu-protocol/src/errors/config.rs Adds the shared-name warning.
crates/nu-protocol/src/config/reedline.rs Defines normalized key identities and tests.
crates/nu-protocol/src/config/mod.rs Implements merging, resetting, and regression tests.
crates/nu-config/default_files/doc_config.nu Documents the new behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/nu-protocol/src/errors/config.rs Resolved
Comment thread crates/nu-protocol/src/errors/config.rs Resolved
Comment thread crates/nu-protocol/src/errors/config.rs Resolved
@kronberger-droid

Copy link
Copy Markdown
Contributor Author

ouch haha... i will fix them soon.

@fdncred

fdncred commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

no worries at all. sometimes copilot gets things right, sometimes not so much.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Yeah I will just think them over and just add tests along the way.

… reads it

`add_parsed_keybinding` treats the modifier as an unordered `_`-joined
set and reads `esc` and `escape` as the same key; `KeyIdentity` compared
the lowered source strings, so `control_shift` vs `shift_control` or
`esc` vs `escape` counted as different keys and a re-key appended and
warned instead of replacing. Modifiers become a component set, `esc`
folds to `escape`. Mode names keep their underscores (`vi_normal` is one
mode, not `vi` + `normal`), pinned by a test. The exotic overlaps
(`space` vs `char_ `, `char_u<hex>`) stay uncanonicalized on purpose: a
mismatch only costs an append plus a warning, never a lost binding.
…content

`ShellWarning::InvalidConfig` reports as `FirstUse` but hashed to `()`,
so every config-warning batch collided in the `ReportLog`: after the
first batch of a session, all later config warnings were suppressed
regardless of content, and `ConfigWarning`'s manual `Hash` never ran.
Delegate to the contained warnings. Dedup is per batch, so a batch that
grows re-shows its earlier warnings alongside the new one.
The label gains its missing verb; the help says the bindings remain in
the configuration rather than promising they all stay active, since
overlapping mode sets still resolve last-write-wins in reedline; the
doc no longer implies an emptied list gets the defaults back on the
next assignment.
@kronberger-droid
kronberger-droid force-pushed the fix/keybinding-merge-shared-names branch from b3fd330 to c015ab3 Compare August 20, 2026 23:32
@kronberger-droid

Copy link
Copy Markdown
Contributor Author

done from my side

@fdncred

fdncred commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

ok, land it when you're ready

@kronberger-droid
kronberger-droid merged commit c8837df into nushell:main Aug 21, 2026
15 checks passed
@github-actions github-actions Bot added this to the v0.116.0 milestone Aug 21, 2026
Paul-16098 added a commit to Paul-16098/Dotfiles that referenced this pull request Aug 21, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Aug 22, 2026
@cptpiepmatz cptpiepmatz modified the milestones: v0.116.0, v0.115.1 Aug 22, 2026
@kronberger-droid
kronberger-droid deleted the fix/keybinding-merge-shared-names branch September 14, 2026 21:36
fdncred pushed a commit that referenced this pull request Nov 4, 2026
…19418)

## Description

Since #18761 assigning `$env.config.keybindings` or `$env.config.menus`
merges into the current list in the config layer.
That made the two lists behave unlike every other list in nushell: `=`
could not drop a single binding, `menus = []` cleared nothing, and a
binding with a bad keycode errored on every prompt until the whole list
was cleared.
#18828 and #18870 patched the merge (unnamed bindings, then name plus
key, with a warning for atuin's shared names in #18848), but each patch
added a rule on top of the merge.

This PR takes the merge out.
Both lists are stored as written, like any other list:

```nu
$env.config.keybindings = [...]                                              # replaces the list
$env.config.keybindings ++= [...]                                            # appends to it
$env.config.keybindings | where name != x                                    # filters it
$env.config.keybindings | reverse | uniq-by modifier keycode mode | reverse  # drops exact repeats
```

Overlaps are resolved where the list is used, by reedline, with one rule
for both lists: entries are applied in order and the last one wins.

| | spot | free spot | taken spot |
|---|---|---|---|
| keybinding | mode, modifier, keycode | filled | replaced |
| menu | name | appended | replaced in place |

Keys already worked like this in reedline, since `add_binding` is a
`HashMap::insert`.
Menus did not, since the lookup by name takes the first match, so
nushell/reedline#1294 made a later menu replace one of the same name.
A keybinding's `name` is only a label and plays no part in what a key
does.

`SharedKeybindingName` goes, since one name on several keys (atuin) is
no longer ambiguous once nothing merges by name.
The `KeyIdentity` machinery that mirrored reedline's key parsing goes
with it.

For keybindings there is a test where nushell hands the list over:
`create_keybindings` is checked for last-wins, for `event: null`
removing a reedline base binding, and for a later entry covering fewer
modes.
Menus rely on the reedline test for the same rule, since nushell only
passes the list on.

## User-facing changes (Release notes)

### Assigning `$env.config.keybindings` and `$env.config.menus` replaces
the list

Breaking: `$env.config.keybindings = [...]` and `$env.config.menus =
[...]` now replace the whole list, including nushell's default menus and
the keys that open them (Tab and Shift+Tab completion, Ctrl+Space, F1
help, Ctrl+X and Ctrl+Z paging, the Ctrl+R history menu).
If your config assigns either list, or sets `keybindings` or `menus`
inside a `$env.config = {...}` record, switch to `++=` or Tab stops
completing.
Reedline's own bindings (movement, editing) are not part of the list and
stay.

```nu
$env.config.keybindings ++= [{ name: my_binding, modifier: control, keycode: char_t, mode: emacs, event: { send: clearscreen } }]
```

To get the defaults back in a running shell, assign them again from a
clean `nu -n`:

```nu
$env.config.keybindings = (^$nu.current-exe -n -c '$env.config.keybindings | to nuon' | from nuon)
$env.config.menus = (^$nu.current-exe -n -c '$env.config.menus | to nuon' | from nuon)
```

Filtering a list now removes what it drops, and `= []` clears either
list.
When several keybindings bind the same key in the same mode, or several
menus share a name, the last one wins.
A keybinding's `name` is only a label, so sharing one between keys no
longer warns.
To unbind a key that reedline itself binds, add an entry for it with
`event: null`.

## Additional notes

Menus need nushell/reedline#1294, which is in the reedline bump commit
before the menus commit.

The book still describes the merge in `line_editor.md` (the keybindings
section and the menus note), so that needs a follow-up PR to
nushell.github.io.

Related: #18761, #18828, #18870, #18848.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.115 keybinding merge-by-name silently drops bindings that share a name across different keys (breaks atuin's ctrl-r)

4 participants