“set -o vi” how to get the yank in the clipboard

Posted on

Problem :

My goal is to yank a line in the shell (for example with yy) into the system clipboard and then paste it somewhere else (for example in the internet browser). How can I accomplish that?

Solution :

The simplest way to get the end result you want (pasting code from shell to internet broswer) is to:

  • Select the text with your mouse cursor
  • Ctrl+Shift+C to copy
  • Ctrl+V to paste outside of terminal
  • Ctrl+Shift+V to paste into a terminal prompt

Your vim need have +xterm_clipboard flag, you can check this with vim --version | grep +xterm_clipboard. If your vim isn’t compiled with this flag, you can compile it yourself or try to install gvim (usually it comes with this flag).

For access to the system clipboard you have to type those sequences:

  • Copy (a word): "*yw
  • Paste: "*p

See: http://vim.wikia.com/wiki/Accessing_the_system_clipboard