Inserting a newline in a multiline zsh command pulled from history

Sean Mackesey picture Sean Mackesey · Oct 16, 2014 · Viewed 14.9k times · Source

Sometimes I use multiline commands in zsh:

❯ echo \
> a \
> multiline \
> command

When editing the command after pulling it from a history search, I can change the content of individual lines. However, I can't figure out how to insert another line:

# I want to insert another line after "multiline"...
❯ echo \
> a \
> multiline \  # but hitting <return> here just runs the command, even though there's a backslash at the end of the line
> command

How can I insert a newline in the middle of a multiline command pulled from history?

Answer

Kamaraju Kusumanchi picture Kamaraju Kusumanchi · May 8, 2016

You can use ESC-Return.

FWIW, I tested it on Debian Jessie, zsh 5.0.7 and it works there.