14

I'm fairly new to Vim. Tonight, I learned about the "yank" command, but when I try to use it in MacVim, it doesn't do anything. Neither Y nor y{motion} do anything. I tried with a default .vimrc to rule out any weird config issues.

Google-fu is failing me. This feels like a noobie issue. Am I missing something obvious?

22

yank by itself merely copies the line into a clipboard - you will need to paste it onto the next line or onto the Preceding one to use the copied line. To cut the line as well, use delete.

  • 1
    Wow, I'm an idiot. I thought that "yank" actually removed the line AND copied it. Ugh, I can't believe I just wasted an hour on this. Thanks @icedwater! – Adam Rubin Jul 10 '13 at 3:06
  • 2
    No problem, you would be looking for delete in that case. – icedwater Jul 10 '13 at 3:13
  • @AdamRubin - And you can skip the yank if you want to cut & paste rather than copy & paste... – jahroy Jul 10 '13 at 3:18
17

If you have the setting set clipboard=unnamedplus in your .vimrc then this will not be working.

For OSX you have to use set clipboard=unnamed

For Linux you will probably need to use set clipboard=unnamedplus

Heres the snippet from my personal .vimrc

if system('uname -s') == "Darwin\n"
  set clipboard=unnamed "OSX
else
  set clipboard=unnamedplus "Linux
endif
  • 1
    Thanks, running OSX here, your tip solved the problem. – Niloct Dec 7 '16 at 1:20
  • 1
    I want to share the same .vimrc across Mac and Linux - is it possible to add some IF inside config? ok I found stackoverflow.com/questions/2842078/… – Vitaly Zdanevich Apr 17 '17 at 6:10
  • @VitalyZdanevich, yes thanks for asking. I have updated the answer with a snippet from my personal config. – Weston Ganger Jun 20 '17 at 16:18
  • 1
    +1 I am using i3 and Vim and have been looking for a solution for a couple of hours now, and this solved my problem. I was able to copy past from applications into Vim, and from Vim to other Vim instances and Terminals but not from Vim into for instance Chromium and other applications. Setting clipboard=unnamedplus solved this issue. Just got lucky stumbling upon this answer. Even though it's an relatively old answer: Thank you sir! Now I can finally continue doing everything with just the my keyboard and put aside the mouse :) – Rens Tillmann Jul 23 '19 at 2:22
  • Thanks for you answer. It solved my problem. My .vimrc have set clipboard=unnamedplus. – Evan Dec 20 '19 at 9:16
5

It does not do anything visible - just like Ctrl-C (Edit/Copy) in other editors. Try the command p (paste) after it - that's the equivalent of Ctrl-V - to put what was yanked into the document.

4

The yank command pulls text into a clipboard. For example yy simply yanks the current line into the common clipboard. You can "paste" the contents of the clipboard with p. You can also yank into named buffers using something like "ayw to yank the text from the current position to the end of the word into a buffer named a. The correspond put is "ap.

  • Yes, that's what I'm expecting it to do, but when I try to use it, it doesn't do anything. I'm trying to use it in normal mode. – Adam Rubin Jul 10 '13 at 3:02
1

If your using Ubuntu or Mint the only solution that seemed to work for me was to uninstall vim and install the package "vim-gnome" instead. Then adding the line:

set clipboard=unnamedplus

to my .vimrc worked as expected.

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.