1

I would like to get Ctrl + V and Ctrl + X to paste / copy from zsh to X11. I found the following snippet to work but zsh does not jump to the character after paste. How could I do that.

copy-to-clipboard () { if [ -n "$LBUFFER$RBUFFER" ]; then echo $LBUFFER$RBUFFER | xclip -i fi } paste-from-clipboard () { CLIPOUT=`xclip -o` BUFFER=$LBUFFER$CLIPOUT$RBUFFER } zle -N paste-from-clipboard paste-from-clipboard zle -N copy-to-clipboard copy-to-clipboard bindkey "^V" paste-from-clipboard bindkey "^X" copy-to-clipboard 
1
  • In copy-to-clipboard, you're adding an extra newline, and it won't work in a few edge cases. Make it print -nr -- $BUFFER | xclip -i Commented Jan 29, 2016 at 19:01

1 Answer 1

1

zsh keeps the position of the cursor in the variable CURSOR so:

paste-from-clipboard () { CLIPOUT=`xclip -o` BUFFER=$LBUFFER$CLIPOUT$RBUFFER CURSOR=$(( $CURSOR + ${#CLIPOUT} )) } 
2
  • or simply LBUFFER+=$(xclip -o) Commented Jan 29, 2016 at 19:00
  • @Gilles is right , small note, don't add spaces to it. Commented Jan 29, 2016 at 21:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.