From the rlwrap
manual:
-m, --multi-line [newline_substitute]
Enable multi-line input using a "newline substitute" character
sequence (" \ ", [space-backslash-space] by default). Newline sub‐
stitutes are translated to newlines before sending the input to
command. With this option, you can call an external editor
$RLWRAP_EDITOR on the (expanded) current input with the
rlwrap_call_editor key (CTRL-^ by default)
When using rlwrap -m
, pressing CTRL+^ will drop you into an editor where you can edit your multi-line snippet. Upon exiting the editor, the snippet will be sent to the rlwrap
ped command, and also be put into the rlwrap
history as one single line (with newlines replaced by the "newline substitute") Moving through history with ↑ and ↓ will still show those snippets as one single line, but you can expand them at any moment into multi-line text within your editor by pressing CTRL+^ again
Not exactly what you're looking for, but it does scroll entire multiline commands at a time, which I like better than e.g. ipython
where you still (at least with the terminals I use) have to press ↑ a couple times to move past a large function definition.
Of course, as with any readline wrapper, there are donwsides: you will lose any context-sensitive completion your CLI might have had, and even the paltry rlwrap
completion mechanism will not work within the multi-line-editor.
Setup:
It should work "out of the box" by just issuing
$ rlwrap -m -a <my_cli_command> # -a because your cli probably
# does some line editing already
Some tweaks:
- If you prefer a diffferent editor, add a line
export RLWRAP_EDITOR='<my_editor_of_choice>[-opts]
in your .bashrc
. The default is vi +%L
. %F
, %L
and %C
in RLWRAP_EDITOR
will be replaced by filename, line and column, respectively, in order to drop you into the editor at the very spot where the cursor was in rlwrap
- To use a different editing hotkey, add a line like
"\C-b":rlwrap-call-editor
to ~/.inputrc
(CTRL+^ is the default)
- To use a different "newline substitute" (e.g. "||") , add an argument to
-m
like in rlwrap -m'||'
(the default is ' \ '
)
- if your
editor_of_choice
does syntax colouring based on filename extensions, add an argument -M.ext
(default: no extension)
For example:
export RLWRAP_EDITOR='my_edit --auto-save-on-exit %F:%L'
# ... or put the above in .bashrc
rlwrap -a -m': ' -M_bas QLSuperBasic # ... those were the days