From e6e9858866c6a11c505b5e4014b49f83ade1b1f1 Mon Sep 17 00:00:00 2001 From: tiynger Date: Sun, 13 Oct 2019 20:51:38 +0200 Subject: [PATCH] fix vi mode zsh copy and paste --- .config/zsh/.zshrc | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 81d22a0..54d7368 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,4 +1,3 @@ - # Disable ctrl-s and ctrl-q. stty -ixon @@ -49,6 +48,42 @@ zle -N zle-line-init echo -ne '\e[5 q' preexec() { echo -ne '\e[5 q' ;} +# Vim copy and paste fix in terminal +function x11-clip-wrap-widgets() { + local copy_or_paste=$1 + shift + for widget in $@; do + if [[ $copy_or_paste == "copy" ]]; then + eval " + function _x11-clip-wrapped-$widget() { + zle .$widget + xclip -in -selection clipboard <<<\$CUTBUFFER + } + " + else + eval " + function _x11-clip-wrapped-$widget() { + CUTBUFFER=\$(xclip -out -selection clipboard) + zle .$widget + } + " + fi + zle -N $widget _x11-clip-wrapped-$widget + done +} + + +local copy_widgets=( + vi-yank vi-yank-eol vi-delete vi-backward-kill-word vi-change-whole-line +) +local paste_widgets=( + vi-put-{before,after} +) + +# NB: can atm. only wrap native widgets +x11-clip-wrap-widgets copy $copy_widgets +x11-clip-wrap-widgets paste $paste_widgets + # starts one or multiple args in background background() { for ((i=2;i<=$#;i++)); do