I have the following in my .zshrc that I'm sure I copied from somewhere. It allows the use of Ctrl-z to also resume programs runnings in the background instead of manually typing fg.
# Allow Ctrl-z to toggle between suspend and resume
function Resume {
fg
zle push-input
BUFFER=""
zle accept-line
}
zle -N Resume
bindkey "^Z" Resume
No. When a program is running in the shell, the default behavior is for Ctrl-z to suspend the program. Nothing needs to be done for that to happen. This snippet runs `fg` when you're back in the shell and press Ctrl-z.
That said, if you wanted to continue running in the background with `bg`, you could make that substitution to allow you to double tap Ctrl-z to do so.
Oh wow I totally misunderstood this snippet; I thought it was in fact the opposite (i.e. a shortcut to send a job to the background). Toggling back to the foreground is even better with the same shortcut! Neat!