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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.