Created
April 22, 2016 05:40
-
-
Save tweekmonster/f4d52ab2069288cd115e0dcea0e47715 to your computer and use it in GitHub Desktop.
zsh edit-command-line zle widget that sets the cursor position in Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function edit-command-line() { | |
tmpfile=$(mktemp -t zsheditXXXXXXXX.sh) | |
print -R - "$PREBUFFER$BUFFER" > $tmpfile | |
editor=${VISUAL:-${EDITOR:-vi}} | |
args=() | |
if [[ "$editor" =~ vim ]]; then | |
pb=${#PREBUFFER} | |
(( b=pb+CURSOR )) | |
args+=("-c" ":call cursor(byte2line($b), ($b - $pb) + 1)") | |
fi | |
args+=($tmpfile) | |
exec </dev/tty | |
$editor ${args[@]} | |
print -z - "$(<$tmpfile)" | |
command rm -f $tmpfile | |
zle send-break | |
} | |
bindkey '^F' edit-command-line | |
zle -N edit-command-line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment