diff options
author | Axel Beckert <abe@deuxchevaux.org> | 2016-12-04 04:32:03 +0100 |
---|---|---|
committer | Axel Beckert <abe@deuxchevaux.org> | 2016-12-04 04:32:03 +0100 |
commit | 3e439c3863f14c82f70666804c8570a13b3732e6 (patch) | |
tree | 07036c43e0f3f9242bb6dd42cd2a849ec8ea8aca /Functions/Zle/vi-pipe | |
parent | 2aedc4b88fd0e87b89583983951b04b96f48efd3 (diff) | |
parent | 7b7e84f0815ed22a0ee348a217776529035dccf3 (diff) | |
download | zsh-3e439c3863f14c82f70666804c8570a13b3732e6.tar.gz zsh-3e439c3863f14c82f70666804c8570a13b3732e6.zip |
Merge tag 'zsh-5.2-test-1' into debian
Diffstat (limited to 'Functions/Zle/vi-pipe')
-rw-r--r-- | Functions/Zle/vi-pipe | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Functions/Zle/vi-pipe b/Functions/Zle/vi-pipe new file mode 100644 index 000000000..1729cb6e1 --- /dev/null +++ b/Functions/Zle/vi-pipe @@ -0,0 +1,39 @@ +# Example of a widget that takes a vi motion + +# Filter part of buffer corresponding to a vi motion through an external +# program. + +# To enable with vi compatible bindings use: +# autoload -Uz vi-pipe +# bindkey -a '!' vi-pipe + +setopt localoptions noksharrays + +autoload -Uz read-from-minibuffer +local _save_cut="$CUTBUFFER" REPLY + +# mark this widget as a vi change so it can be repeated as a whole +zle -f vichange + +# force movement to default to line mode +(( REGION_ACTIVE )) || zle -U V +# Use the standard vi-change to accept a vi motion. +zle .vi-change || return +read-from-minibuffer "!" +zle .vi-cmd-mode +local _save_cur=$CURSOR + +# cut buffer contains the deleted text and can be modified +CUTBUFFER=$(eval "$REPLY" <<<"$CUTBUFFER") + +# put the modified text back in position. +if [[ CURSOR -eq 0 || $BUFFER[CURSOR] = $'\n' ]]; then + # at the beginning of a line, vi-delete won't have moved the cursor + # back to a previous line + zle .vi-put-before -n 1 +else + zle .vi-put-after -n 1 +fi + +# restore cut buffer and cursor to the start of the range +CUTBUFFER="$_save_cut" CURSOR="$_save_cur" |