2

I recently moved from bash to zsh and use vim keybindings in zsh.

When I highlight a string in visual and yank it with y, I can then paste it inside of zsh without problem. However when I try to paste that same string outside of zsh (with the command Ctrl + d) it does not work. Instead the last copied item with Ctrl + c is copied there.

Is there an additional command to write in the .zshrc?

ecjb
  • 4,291
  • 11
  • 31
  • 67
  • Shells have their own internal buffers. You could use something like pbcopy/xclip depending on your system – D. Ben Knoble Apr 28 '20 at 13:37
  • Many thanks for your comment @D.BenKnoble. Do you have any idea about which command I should write in the `.zshrc`? – ecjb Apr 28 '20 at 13:47

2 Answers2

4

By default zsh yanks to its own internal registers. Luckily, like in Vim, it's fairly simple yank to the system clipboard.

# vi mode
bindkey -v

# Yank to the system clipboard
function vi-yank-xclip {
    zle vi-yank
   echo "$CUTBUFFER" | pbcopy -i
}

zle -N vi-yank-xclip
bindkey -M vicmd 'y' vi-yank-xclip

Replace pbcopy with the method of your system, for example xclip if you're on Linux.

Further reading and a couple alternatives at:

(Which this question is a duplicate of.)

-1

You first have to be sure that your vim installation has clipboard support. Open vim and type:

:version

You'll see the features included in your installation have a + next to them, those that aren't have a -, for example:

Huge version with GTK2 GUI.  Features included (+) or not (-):
.
.
.

+clientserver      -footer            +mouse_netterm     +smartindent       +wildmenu
+clipboard         +fork()            +mouse_sgr         +startuptime       +windows
.
.
.

^^^^^^^^^^^^^ see here that clipboard is included. If you don't have clipboard support, see this stackoverflow answer on how to get it in MacOS.

Once you have +clipboard you can yank into the system clipboard by first typing "+ to tell vim to use the '+ register' (see How do I use vim registers?), followed by the normal y to yank the text.

compuphys
  • 1,080
  • 9
  • 26