From 0f6e49b455e498bd051d1d18d62dec4e6872d3e8 Mon Sep 17 00:00:00 2001 From: "Daniel Campoverde [alx741]" Date: Fri, 20 Feb 2015 13:13:17 -0500 Subject: [PATCH] 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. --- plugins/vi-mode/vi-mode.plugin.zsh | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 950f69724..d4c198782 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -63,3 +63,45 @@ function vi_mode_prompt_info() { if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then RPS1='$(vi_mode_prompt_info)' 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 +}