Skip to content

fix(config)!: make assigning keybindings and menus replace the list - #19418

Merged
fdncred merged 3 commits into
nushell:mainfrom
kronberger-droid:fix/config-lists-replace
Nov 4, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
kronberger-droid:fix/config-lists-replace

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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:

$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.

$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:

$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.

@github-actions

github-actions Bot commented Nov 3, 2026

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.

@kronberger-droid
kronberger-droid force-pushed the fix/config-lists-replace branch from 06dc130 to 5115138 Compare November 3, 2026 10:14
Comment thread crates/nu-cli/src/reedline_config.rs Resolved

@fdncred fdncred 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.

Review overview

🟡 Changes recommended

=, ++=, filtering and = [] do what the PR says on both lists, and ++= keeps Tab completion working. One regression: a broken menu or keybinding now outlives a later fix, so reloading a fixed config no longer recovers. The rest is docs.

Findings: 0 High severity · 1 Medium severity · 3 Low severity

Open (4)

Notes from my clanker, checked on 5115138. Built the branch (its reedline fork is 8bc5cd0 plus nushell/reedline#1294 and nothing else) and ran each case on it and on 0.116.2, with Tab checked in a real REPL. CI already ran fmt, clippy and the tests on all three OSes, so I didn't rerun them. The security_audit failure is calamine's RUSTSEC-2026-0436, which fails on main too.

Comment on lines +260 to +263
// Stored as written, like any list. Reedline registers the
// menus in order, so a later one wins on a name.
"menus" => match Vec::<ParsedMenu>::from_value(val.clone()) {
Ok(menus) => {
for menu in menus {
let target_name = menu.name.to_expanded_string("", self);

let found_index = self.menus.iter().position(|existing_menu| {
existing_menu.name.to_expanded_string("", self) == target_name
});

if let Some(index) = found_index {
self.menus[index] = menu;
} else {
self.menus.push(menu);
}
}
}
Ok(menus) => self.menus = menus,

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.

Medium severity A broken entry still fails the list after a later one replaces it

On 5115138, a later entry doesn't replace an earlier broken one. Every entry still gets built, so the broken one fails first. You hit this when you fix an entry in config.nu and reload it, because ++= appends the fixed copy after the broken one.

Menus:

# menu_bad.nu:   $env.config.menus ++= [{name: completion_menu, only_buffer_difference: false, marker: "X ", type: {layout: grid}, style: {}}]
# menu_fixed.nu: the same with `layout: columnar`
source menu_bad.nu; source menu_fixed.nu
$env.config.menus | where name == completion_menu | get type.layout | to nuon
# main:   [columnar]
# branch: [columnar, grid, columnar]

# then `"ab" | str capitali<Tab><Enter>` in the REPL
# main:   completes to `str capitalize`, prints Ab
# branch: `expected 'columnar', 'list', 'ide', or 'description', but got 'grid'` at every prompt, and Tab does nothing

Keybindings, same name and key with a bad event first:

# kb_bad_event.nu: $env.config.keybindings ++= [{name: my_binding, modifier: control, keycode: char_t, mode: emacs, event: {send: bogus}}]
# kb_fixed.nu:     the same with `event: {send: clearscreen}`
source kb_bad_event.nu; source kb_fixed.nu
$env.config.keybindings | where name == my_binding | get event.send | to nuon
# main:   [clearscreen], and no error at the next prompt
# branch: [bogus, clearscreen], and `expected a reedline event, but got 'bogus'` at every prompt

On main the merge replaced the broken entry, so reloading the fixed config (source $nu.config-path, or an F5 binding that runs it) recovered. On the branch it stays broken until a restart or a where filter, even though doc_config.nu says the last entry wins.

For menus, building only the last menu for each name in add_menus (reedline_config.rs:37) makes that hold for broken menus too:

for (i, menu) in config.menus.iter().enumerate() {
    let name = menu.name.to_expanded_string("", &config);
    // A later menu with this name replaces this one, so don't build it.
    if config.menus[i + 1..]
        .iter()
        .any(|later| later.name.to_expanded_string("", &config) == name)
    {
        continue;
    }
    line_editor = add_menu(line_editor, menu, engine_state_ref.clone(), stack, config.clone())?
}

I tried this as a trial patch on the branch: after the same reload, Tab completes again and the error is gone. It also stops building the shadowed copies on every prompt, and it gives nushell a test for the last-wins rule instead of leaning only on the reedline one.

For keybindings the key decides, not the name, so create_keybindings would have to walk the list from the end and skip a mode and key that a later entry already set. That gives the same last-wins result, and it never reads the shadowed entry's event.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fdncred
How about checking the entries when the list is assigned and rejecting the whole list if one is faulty, like table.mode = "bogus" errors and keeps the old value?
That covers modifier, keycode and mode (and a menu's layout), thus a reload with a fixed config recovers, but events like {send: bogus} would still only fail when the prompt is built.

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.

true

@fdncred

fdncred commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

I also have a PR for the security audit cooking right now

Note: it landed #19420 - just need to merge main to get the ci green

@fdncred

fdncred commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

I also wonder about this keybinding that I have. Seems like it duplicates menus and keybindings.

  {
    name: reload_config
    modifier: none
    keycode: f5
    mode: [emacs vi_normal vi_insert]
    event: {
      send: executehostcommand,
      cmd: $"source '($nu.env-path)';source '($nu.config-path)'"
    }
  }

Does $env.config.keybindings = [] remove the keybindings that can't be assigned? I think there are some hardcoded keybindings that nushell doesn't support changing because we don't have the syntax so they're hard coded in rust. You may have changed this so I'm not sure. Just want to make sure this doesn't throw away things with no way to get them back except exit and restart.

fdncred added a commit that referenced this pull request Nov 3, 2026
## Description

The `Security audit` job fails on every PR that touches `Cargo.toml` or
`Cargo.lock` (for example #19418), and on main's lockfile too. The
advisory database now flags calamine 0.37.0 with RUSTSEC-2026-0436: a
crafted file can make calamine's CFB/OLE2 reader panic or try to
allocate several gigabytes. calamine 0.38.0 fixes it.

nushell can hit this bug. `from xlsx` runs the CFB reader on every input
to check for password protection, so the upstream fixture
`cfb_dir_short_chunk_panic.xls` (calamine PR #762) crashes the shell on
main.

| Crate | Old | New | Advisory | Pulled in by |
| --- | --- | --- | --- | --- |
| `calamine` | 0.37.0 | 0.38.0 | RUSTSEC-2026-0436 | `nu-command` (`from
xlsx`, `from ods`) |


## User-facing changes (Release notes)

- `from ods` now returns a formula error cell's text (such as `#DIV/0!`)
instead of an empty string, and keeps tabs and line breaks inside cell
text.
- Fixed `from xlsx` crashing nushell or running out of memory on a
crafted file. It now reports `Could not load XLSX file`
(RUSTSEC-2026-0436).

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
@kronberger-droid
kronberger-droid force-pushed the fix/config-lists-replace branch from 5115138 to bc4205e Compare November 3, 2026 22:44
Since nushell#18761 assigning `$env.config.keybindings` merged into the
current list, thus no assignment could drop a single binding, and a
binding with a bad keycode errored on every prompt until the whole
list was cleared.

The list is now stored as written, like any other list: `=` replaces
it, `++=` appends and a filtered list drops what it filtered out.
Reedline applies the entries in order on top of its base maps, so the
last entry on a key wins, in each mode it names. A name is only a
label.

`= [mine]` now drops the default menu bindings as well, since nushell#18747
moved them into the list. Use `++=` to keep them.

`SharedKeybindingName` goes: one name on several keys (atuin) is no
longer ambiguous once nothing merges by name.
Brings in nushell/reedline#1294, which the menus commit after this one
relies on.
Same semantics as the keybindings commit before it: the list is stored
as written, thus `=` replaces it, `= [mine]` drops the defaults and
`++=` keeps them.

A menu added under a taken name overrides it, since reedline registers
the menus in order and the last one under a name wins
(nushell/reedline#1294). That needs the reedline bump below this commit.
@kronberger-droid
kronberger-droid force-pushed the fix/config-lists-replace branch from bc4205e to 4312b18 Compare November 3, 2026 22:55
@kronberger-droid

Copy link
Copy Markdown
Contributor Author

@fdncred
Yeah = [] clears only entries which are in $env.config.keybindings, and reedline's base maps are applied underneath anyways. So not a full clear.

Also yeah if you reload with a ++= you will have duplicates, which reedline does not care about, but the list grows by a copy per reload.

My idea behind this implementation was to make no special casing and treat both menus and keybindings just like lists.
So you could change it to not duplicate, but it would be more than just ++=, you drop the old entry first:

$env.config.keybindings = $env.config.keybindings | where name? != reload_config | append {...}

My idea would be similar to your suggestion on discord, make keybinding ... commands that are easier to use and don't clobber list semantics with special casing.
That would be a follow-up I guess.

@fdncred

fdncred commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

I'm fine with keybinding commands as follow ups but I don't really like the idea of an ever growing list of keybindings and menus. I think we should deduplicate in code before merging. My keybinding doesn't do ++=, is just sources config.nu and env.nu.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Well then it depends on how you set keybindings in your config. If you don't dedup there but just do ++= then you get dublicates. If you do = you don't.

Form Keeps the defaults Safe to reload
$env.config.keybindings = [mine] no yes, the same list is assigned each time
$env.config.keybindings ++= [mine] yes no, it grows by a copy per reload
$env.config.keybindings = ($env.config.keybindings | where name? != x | append {...}) yes yes

@kronberger-droid

kronberger-droid commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

I would prefer just making it easy, but explicit to dedup.
Duplicates are not a problem for reedline. It more a resource question.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

In my mind the only thing that is really missing is a way to get the defaults as data, since the only way today is ^$nu.current-exe -n -c '$env.config.keybindings | to nuon' | from nuon.
With that, a reset line at the top of the config makes every ++= below it reload safe:

$env.config.keybindings = (<defaults>)
$env.config.keybindings ++= [mine]

@fdncred

fdncred commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

I don't use ++= anywhere in my configs. My macos config is written "old-style". So, I don't think any of that should append. Let me do some more checking to see if I really get dupes or if I'm just assuming. LOL

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Well with plain = you would just replace the defaults but not duplicate.

@fdncred

fdncred commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Just what I was speculating, I don't get dupes now with F5 now. I actually get less items because my F5 (not a problem of this PR) does not reload the autoloads folders/files.

I think we're good to go now with this incremental change. If we need/want to dedupe in the future we still can.

@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes notes:breaking-changes Noted in Breaking Changes section and removed notes:fixes Noted in "Bug fixes" section labels Nov 4, 2026
@fdncred
fdncred merged commit 674c49c into nushell:main Nov 4, 2026
13 checks passed
@github-actions github-actions Bot added this to the v0.117.0 milestone Nov 4, 2026
kronberger-droid added a commit that referenced this pull request Nov 5, 2026
…t read (#19438)

## Description

Follow-up to #19418.
A keybinding or menu with a modifier, keycode, mode, layout, input mode
or output mode that can't be read used to be accepted and then failed at
every prompt.
A fixed copy that a reload appended did not replace it, since `++=` only
adds, thus Tab stayed broken until a restart.

Assigning such a list is now rejected as a whole and the previous list
stays, like for any other config value that can't be read.
The grammar moved from `nu-cli` to `nu-protocol` (`config/key_spec.rs`)
for that, since `nu-protocol` has no `crossterm`, and `nu-cli` only maps
it onto reedline's types.

This also adds `config default`, which returns the default config as a
record.
A config that gets sourced again needs it to start from the defaults,
and it replaces the `^$nu.current-exe -n -c ...` hack in
`doc_config.nu`.

## User-facing changes (Release notes)

- Assigning `$env.config.keybindings` or `$env.config.menus` with an
entry that can't be read is now an error, and the old list is kept.
That covers the `modifier`, `keycode` and `mode` of a keybinding, and
the `layout`, `input_mode` (or `only_buffer_difference`) and
`output_mode` of a menu.
  Before, it was accepted and failed on every prompt.
  In `config.nu`, the lines after the rejected assignment don't run.
- A menu without a `layout`, such as `type: {}`, is rejected on
assignment now.
- New command `config default`, which returns the default config as a
record.
A config that is sourced again adds its `++=` entries each time, and `=`
drops the defaults, so start from the defaults to keep the list stable:

  ```nu
  $env.config.keybindings = (config default).keybindings
  $env.config.keybindings ++= $custom
  ```

## Additional notes

Unit tests in `nu-protocol` cover the grammar and the rejected lists,
and repl tests cover the reload scenario.

Out of scope:

- `event` and the fields of one menu layout (`columns`, `page_size`,
`description_position`) are still read when the prompt is built.
- The error names the first bad entry and not the setting. One error per
bad entry would be a follow-up.
- `nu-tui` still reads keybinding strings with its own looser rules
(`normalize_binding`).

---------

Co-authored-by: Darren Schroeder <[email protected]>
yamadayuki added a commit to yamadayuki/dotfiles that referenced this pull request Nov 12, 2026
…ults

Nushell 0.117.0 (nushell/nushell#19418) made assigning keybindings/menus
inside $env.config = {...} replace the whole list, including the default
bindings that open Tab completion, Ctrl+Space, F1 help, Ctrl+X/Z paging,
and Ctrl+R history. Switch to $env.config.menus ++= / keybindings ++= so
custom entries add to the defaults instead of wiping them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants