Vim "yank" does not seem to work
Asked Answered
C

5

32

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?

Cardiganshire answered 10/7, 2013 at 2:50 Comment(4)
What does Y do? Did you mean y?Mccomb
@icedwater: Y is a synonym for yy.Salado
Ah, thanks @Salado - I'd never use it since yy is much faster than going to the shift key for me. Good to know though.Mccomb
Thank you for asking this question! It was driving me crazy too. I kept trying to paste from the system clipboard. ;-)Wring
M
28

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.

Mccomb answered 10/7, 2013 at 3:2 Comment(3)
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!Cardiganshire
No problem, you would be looking for delete in that case.Mccomb
@AdamRubin - And you can skip the yank if you want to cut & paste rather than copy & paste...Gaston
B
61

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
Brittenybrittingham answered 4/9, 2016 at 3:13 Comment(6)
Thanks, running OSX here, your tip solved the problem.Uniocular
I want to share the same .vimrc across Mac and Linux - is it possible to add some IF inside config? ok I found #2842578Tomblin
@VitalyZdanevich, yes thanks for asking. I have updated the answer with a snippet from my personal config.Brittenybrittingham
+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 :)Prochora
Thanks for you answer. It solved my problem. My .vimrc have set clipboard=unnamedplus.Flock
I had a linux vimrc and I moved to a new OSX machine and ran into this!Preoccupied
M
28

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.

Mccomb answered 10/7, 2013 at 3:2 Comment(3)
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!Cardiganshire
No problem, you would be looking for delete in that case.Mccomb
@AdamRubin - And you can skip the yank if you want to cut & paste rather than copy & paste...Gaston
S
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.

Salado answered 10/7, 2013 at 2:55 Comment(0)
S
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.

Schlessel answered 10/7, 2013 at 2:57 Comment(1)
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.Cardiganshire
V
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.

Valenta answered 28/11, 2014 at 4:40 Comment(1)
unnamedplus only works on Linux. OSX uses unnamedBrittenybrittingham

© 2022 - 2024 — McMap. All rights reserved.