You can use self-insert-unmeta to bind Alt + Return to insert a literal new line without accepting the command:
bindkey '^[^M' self-insert-unmeta
To use your example: pressing Alt + Return at the cursor position ( # )
% echo \ a \ multiline \
You will get the following:
% echo \ a \ multiline \
This works not only when editing history, but also when typing commands. This way you can prepare several script-style commands and accept them with a single Return .
For example, pressing Alt + Return instead of # in this example:
% echo command 1
will do the same as echo command 1; echo command 2; echo command 3 echo command 1; echo command 2; echo command 3 echo command 1; echo command 2; echo command 3 , and will produce this output:
command 1 command 2 command 3
source share