3

I'd like to yank text from a zsh command while in vi-mode with y and paste it into my web-browser/text-editor, etc.

Currently it seems that yanking text while in vi-mode only allows pasting back into zsh- has anyone had success yanking into the system clipboard?

lsankar4033
  • 509
  • 3
  • 14

1 Answers1

4

Create a widget that executes the internal vi-yank widget and copies the zle clipboard (current position in kill ring) to the X11 clipboard using xclip(1):

function vi-yank-xclip {
    zle vi-yank
   echo "$CUTBUFFER" | xclip -i
}

.Replace xclip -i with pbcoby if running Mac OSX.

Make that widget known to zle and bind it to y:

zle -N vi-yank-xclip
bindkey -M vicmd 'y' vi-yank-xclip
kba
  • 1,117
  • 9
  • 20