nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
517 stars 140 forks source link

Default keybind for "newline" #792

Open NotTheDr01ds opened 3 months ago

NotTheDr01ds commented 3 months ago

Nushell pipelines are best split over multiple lines, and the nufmt specification recommends "wall of pipes" formatting. E.g.:

ls
| where size > 0kb
| insert name_length {$in.name | str length}

However, that's extremely tedious to create "out of the box" with Nushell/Reedline at the moment, since a Enter only creates a newline in this case if there's a trailing pipe character on the existing line. E.g.:

In order to create the "wall of pipes", you have to start with the first form ls |, hit Enter , then continue your | pipeline, and then (if you're pedantic) remove the trailing pipe from the previous line. You could also do something like start the pipeline with a ( open-paran to keep Enter from executing the pipeline until complete.

While it's relatively easy for a user to create a keybinding in their config to map Alt+Enter (assuming macOS ?), given the importance of newline in Nushell CLI-usage, I'd recommend this be a built-in keybinding.

Note: This is built-in to the Fish shell.

fdncred commented 3 months ago

Ya, I've always thought the pipes belong on the right side for the same reasons. I have this in my keybindings because the problem with alt-enter is that it's not free in all terminals.

  {
    name: insert_newline
    modifier: alt
    keycode: char_i
    mode: [emacs vi_normal vi_insert]
    event: { edit: insertnewline }
  }
  {
    name: insert_newline
    modifier: alt
    keycode: enter
    mode: [emacs vi_normal vi_insert]
    event: { edit: insertnewline }
  }

But I wouldn't have a problem with adding these to the default_config.nu and in the rust code.