Fish-like Multiline Editing in Bash

Nov 19, 2025

A feature that I really liked about Fish was the possibility to edit multiline commands on the command line. In the first place, I just made friends with ; and \, but when I decided to migrate msm from Fish to the Posix shell, I started to have the need for multiline editing, as I wanted to add a description to the snippet. Here’s an example of snippet format:

# one-line description (optional)
snippet --definition

I needed a way to write multiline commands in Bash, without awkward workarounds. Here is how I did it.

add_newline() {
    local region="${READLINE_LINE:0:READLINE_POINT}"
    local after="${READLINE_LINE:READLINE_POINT:${#READLINE_LINE}}"

    READLINE_LINE="$region
$after"
    ((READLINE_POINT++))
}

bind -x '"\e\r": add_newline'

This command adds a newline under your cursor, without running the command. I bound it to Alt-Enter, which is also how this was achieved in Fish.