28

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?

Jarrod
  • 9,349
  • 5
  • 58
  • 73
Adam Rubin
  • 777
  • 1
  • 7
  • 16

5 Answers5

54

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
Weston Ganger
  • 6,324
  • 4
  • 41
  • 39
  • 4
    Thanks, running OSX here, your tip solved the problem. – Niloct Dec 07 '16 at 01: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 http://stackoverflow.com/questions/2842078/how-do-i-detect-os-x-in-my-vimrc-file-so-certain-configurations-will-only-appl – Vitaly Zdanevich Apr 17 '17 at 06: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 02:22
  • Thanks for you answer. It solved my problem. My `.vimrc` have `set clipboard=unnamedplus`. – Evan Knox Thomas Dec 20 '19 at 09:16
  • I had a linux vimrc and I moved to a new OSX machine and ran into this! – Alfredo Gallegos May 12 '22 at 21:05
27

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.

icedwater
  • 4,701
  • 3
  • 35
  • 50
  • 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 03:06
  • 2
    No problem, you would be looking for `d`elete in that case. – icedwater Jul 10 '13 at 03:13
  • @AdamRubin - And you can skip the yank if you want to **cut** & paste rather than **copy** & paste... – jahroy Jul 10 '13 at 03:18
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.

Amadan
  • 191,408
  • 23
  • 240
  • 301
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.

D.Shawley
  • 58,213
  • 10
  • 98
  • 113
  • 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 03: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.

rod howard
  • 141
  • 1
  • 6