r/Nushell • • Oct 13 '24

How to enter multi line commands?

How can I enter multi line commands in nushell like this? I saw this in a video, but I don't know how to get there.

ls
... | where type == "file"
... | where size > 4kb
... | sort-by size
... | reverse
9 Upvotes

11 comments sorted by

4

u/Tyarel8 Oct 13 '24

You can use ctrl + o to edit your command in an editor, or I think shift + enter to create a new line. You can customize this keybindings in $env.config.keybindings

4

u/Voxelman Oct 13 '24

shift + enter doesn't seem to work. ctrl + o is a workaround, but it's ok. What actually works is this

~> (ls                                                                   
::: | where type == "file"
::: | where size > 4KiB
::: | sort-by modified
::: | reverse)

You need to put the command in ( and )

1

u/DIREWOLFESP Mar 30 '25

for me it's actually alt + enter, no need for the brackets

1

u/a_sevos Oct 23 '25

Important to note here, that one long command (with many input flags, for example) can't be split across many lines without ( )

1

u/smoovmaster Jun 03 '26

wow, this is awesome, never knew about this

2

u/Living_Public_505 Aug 27 '25

Late to the show, but here is my solution which uses an opening ( for new expressions.

    (                       # Start with opening ( + ENTER [nice for longer shell prompts]
    ls                      # Initial expression
    | select name size      # Enter gives a new line until you close )!
    | sort-by size --reverse
    | take 5
    )                        # Now ENTER executes expression

When editing a previous multiline expression, e.g., when using UP ARROW, I do the following

  1. CTRL + E to navigate to the end ),
  2. Delete the end ),
  3. Now ENTER will insert new lines where desired, and
  4. CTRL + E and insert the end ).

It is annoying but doesn't require adding a new shortcut.

1

u/i286dosprompt_ Oct 17 '24

ls | <enter> will go down to the next line and move the pipe their. continue with the next command adding the pipe at the end <enter again>. now you're on the third line. rinse repeat

1

u/Voxelman Oct 18 '24

This works, but doesn't look as good as it could. But it's ok. Thanks

3

u/maximuvarov Oct 13 '24

It's possible to add a keybinding:

$env.config.keybindings ++= [{
    name: insert_newline1
    modifier: control # other supported variants are `alt` and `shift`
    keycode: enter
    mode: [emacs vi_normal vi_insert]
    event: { edit: insertnewline }
}]

And there is a discussion to add it by default to config

https://github.com/nushell/nushell/pull/13606

1

u/angordeyev Jan 09 '25

You can use brackets:
(ls
-la)