I type Ctrl+Z to “suspend” the command I'm typing and type another command. After I've run that command (or aborted it with Ctrl+C), the suspended command comes back for edition (even remembering the cursor position). As an additional convenience, if the command line is empty when I type Ctrl+Z, the key invokes the bg
built-in instead (so a double Ctrl+Z sends a running command directly to the background).
fancy-ctrl-z () {
emulate -LR zsh
if [[ $#BUFFER -eq 0 ]]; then
bg
zle redisplay
else
zle push-input
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
(Previously posted at Remember a half-typed command while I check something which mainly has solutions for bash, where you can't do anything so convenient. This is a slightly fancier version of the built-in binding of M-q
to push-line
.)
This doesn't run a subshell: the command that you type after “suspending” the previous one runs in the same shell. This lets you do things like changing the current directory if you realize after typing a command that you meant to run it in a different directory. If you want to run a new shell instance, you can run zsh
from a key binding, but I don't think that's particularly useful.
screen
ortmux
to get multiple virtual terminals on the console. – Barmar Mar 14 '19 at 14:51