2

I've build myself this little script for zsh, to copy & paste within zsh to the system clipboard (basically got everything from here: zsh copy and paste like emacs)

x-yank() {
    zle copy-region-as-kill
    print -rn -- $CUTBUFFER | pbcopy
}
zle -N x-yank

x-cut() {
    zle kill-region
    print -rn -- $CUTBUFFER | pbcopy
}
zle -N x-cut

x-paste() {
    CUTBUFFER=$(pbpaste)
    zle yank
}
zle -N x-paste

bindkey -M vicmd "y" x-yank
bindkey -M vicmd "Y" x-cut
bindkey -M vicmd "p" x-paste

However, there are a few minor problems, which I can't seem to get fixed:

  • Pasting will remove the current char which under the cursor, I would much prefer the Vim way, to insert it afterwards.
  • Copying will not remove the selection.

Any ideas where to get started?

Leandros
  • 712
  • 2
  • 7
  • 16

1 Answers1

1

Ok, figured it out, I could just manipulate the different buffers directly:

x-paste() {
    PASTE=$(pbpaste)
    LBUFFER="$LBUFFER${RBUFFER:0:1}"
    RBUFFER="$PASTE${RBUFFER:1:${#RBUFFER}}"
}
zle -N x-paste

bindkey -M vicmd "p" x-paste
Leandros
  • 712
  • 2
  • 7
  • 16
  • 1
    This answer is unclear. Did you substitute all of the code in your original question with just the above code or did your replace the pertinent lines in your question code with the code above? – Jim Aug 17 '19 at 19:24