PLUGINS: vi-mode: Allow Copy/Paste with the clipboard

Enable to use vim commands ( y/p/d/c/s ) to interact with the X window
system clipboard, thus with other applications.
This commit is contained in:
Daniel Campoverde [alx741] 2015-02-20 13:13:17 -05:00
commit 0f6e49b455

View file

@ -63,3 +63,45 @@ function vi_mode_prompt_info() {
if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
RPS1='$(vi_mode_prompt_info)' RPS1='$(vi_mode_prompt_info)'
fi fi
# Allow Copy/Paste with the system clipboard
# behave as expected with vim commands ( y/p/d/c/s )
[[ -n $DISPLAY ]] && (( $+commands[xclip] )) && {
function cutbuffer() {
zle .$WIDGET
echo $CUTBUFFER | xclip -selection clipboard
}
zle_cut_widgets=(
vi-backward-delete-char
vi-change
vi-change-eol
vi-change-whole-line
vi-delete
vi-delete-char
vi-kill-eol
vi-substitute
vi-yank
vi-yank-eol
)
for widget in $zle_cut_widgets
do
zle -N $widget cutbuffer
done
function putbuffer() {
zle copy-region-as-kill "$(xclip -o)"
zle .$WIDGET
}
zle_put_widgets=(
vi-put-after
vi-put-before
)
for widget in $zle_put_widgets
do
zle -N $widget putbuffer
done
}