# 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 == 1 )); then if (( CURSOR < MARK )); then left=$CURSOR right=$MARK else left=$MARK right=$CURSOR fi lbuffer=$lbuffer[++left,-1] buffer=$BUFFER[left,++right] elif (( REGION_ACTIVE == 2 )); then local nl=$'\n' if (( CURSOR < MARK )); then left=${${BUFFER[1,CURSOR]}[(I)$nl]} right=${${BUFFER[MARK+1,-1]}[(i)$nl]} (( right += MARK )) else left=${${BUFFER[1,MARK]}[(I)$nl]} right=${${BUFFER[CURSOR+1,-1]}[(i)$nl]} (( right += CURSOR )) fi lbuffer=$lbuffer[++left,-1] if [[ $BUFFER[right] = $nl ]]; then # Keep the newline because "$(<$1)" below trims it (( --right )) fi 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")