diff options
Diffstat (limited to 'Functions')
-rw-r--r-- | Functions/Zle/edit-command-line | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 100af9601..2ad4825b7 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -8,7 +8,17 @@ () { exec </dev/tty - ${=${VISUAL:-${EDITOR:-vi}}} $1 + + # Open the editor, placing the cursor at the right place if we know how. + local editor=${${VISUAL:-${EDITOR:-vi}}} + integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) + case $editor in + (*vim*) ${=editor} -c "normal! ${byteoffset}go" -- $1;; + (*emacs*) ${=editor} $1 -eval "(goto-char ${byteoffset})";; + (*) ${=editor} $1;; + esac + + # Replace the buffer with the editor output. print -Rz - "$(<$1)" } =(<<<"$PREBUFFER$BUFFER") |