# Edit the command line using your usual editor. # Binding this to '!' in the vi command mode map, # autoload -Uz edit-command-line # zle -N edit-command-line # bindkey -M vicmd '!' edit-command-line # will give ksh-like behaviour for that key, # except that it will handle multi-line buffers properly. emulate -L zsh local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER local TMPSUFFIX=.zsh # set up parameters depending on which context we are called from, # see below comment for more details if (( REGION_ACTIVE )); then if (( CURSOR < MARK )); then left=$CURSOR right=$MARK lbuffer= else left=$MARK right=$CURSOR lbuffer[right-left,-1]= fi (( left++ )) buffer=$BUFFER[left,right] elif (( ! ZLE_RECURSIVE )); then prebuffer=$PREBUFFER fi () { exec CURSOR )); then (( MARK += $#BUFFER - prelen )) else (( CURSOR += $#BUFFER - prelen )) fi elif [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then BUFFER="$(<$1)" else print -Rz - "$(<$1)" zle send-break fi } =(<<<"$prebuffer$buffer")