How can I copy into the Mac clipboard from vim?

6

I can paste from vim in one terminal window to vim in another, but not to anything outside vim. I've read numerous posts on the subject, and nothing I've found has helped. Copy/pasting from MacVim works, but I prefer using VIM.

I'm using OSX 10.7.5 and Vim 7.4, installed via MacPorts.

vim --version 

shows +clipboard, +x11, +xterm_clipboard.

I've tried "+y, "*y combined with both visual selection and range selection.

In my ~/.vimrc , I've got

set clipboard=unnamedplus,unnamed,autoselect

EDIT:

Solution found! Now, y, yy and so on work perfectly! Whatever I yank in Vim, I can paste outside, and whatever I command-c outside, I can p in Vim.

The solution: As per FDinof's suggestion, I reinstalled via MacPorts WITHOUT x11, instead just doing

sudo -v port install vim +huge

For the record, I still have

set clipboard=unnamedplus,unnamed,autoselect

in my ~/.vimrc

Thank you for your help!

Reefersleep

Posted 2013-12-19T03:36:00.413

Reputation: 73

2x11 isn't needed for this since mac doesn't use x11. However everything else looks fine. – FDinoff – 2013-12-19T04:52:00.563

I'm curious as to why I've seen suggestions that you should compile/install with x11, then. From what I can google, Apple has dropped support for x11, but maybe Vim clipboard support just still requires x11 to work properly for some reason? I must say, it's annoying for the x11 app to appear in the dock whenever I'm using Vim, so if I can get what I want without x11, I'd certainly prefer that. – Reefersleep – 2013-12-28T15:13:03.867

1Recompile vim without x11. I don't have it and I can copy to the clipboard. My guess is that you are copying to the x11 clipboard which you don't know how to access from the mac side. – FDinoff – 2013-12-28T17:17:58.173

The only variants I use are +huge and +python27 when I installed vim through macports – FDinoff – 2013-12-28T17:25:19.487

FDinoff, you are right - recompiled without x11, now y, yy and so on works perfectly! Don't know why it didn't work before. Maybe I wasn't systematic enough in my testing. – Reefersleep – 2014-01-11T22:09:32.870

Answers

1

x11 isn't needed for copying to the clipboard since mac doesn't use x11. Recompile vim without x11. My guess is that you are copying to the x11 clipboard which you don't know how to access from the mac side.

In macports using the huge variant is sufficient to get clipboard support working.

port install vim +huge

FDinoff

Posted 2013-12-19T03:36:00.413

Reputation: 1 623

6

From memory in Vim you can use pbcopy and pbpaste the same way as any other external command. To copy the current line to the clipboard type:

:.!pbcopy

to copy lines 1 to 50

:1,50!pbcopy

To copy the contents of the clipboard into the current vim bufer use:

:r !pbpaste

Antony

Posted 2013-12-19T03:36:00.413

Reputation: 1 125

1

further reading http://blog.ijun.org/2011/03/copy-selection-to-os-x-system-clipboard.html

– Antony – 2013-12-19T08:40:00.353

Maybe I asked my question wrong - I've come upon the pbcopy/pbpaste solution as well, but what I'd really like is for y, yy and so on to copy into the clipboard, so I can paste into stuff outside of Vim - and for p to paste from the clipboard. Binding pbcopy and pbpaste to ctrl c/v, as you have suggested in your linked blog post, is a working solution, but not entirely satisfying - I use Vim to have shortcuts like p and y at my fingertips, and having to use ctrl c/v in SOME situations seems redundant and confusing. I'm new to posting on stack -should I rephrase my original question? – Reefersleep – 2013-12-28T14:49:51.390

1Use :reg to check what's in your registers after using y yy +Y etc May give a clue to what is wrong – Antony – 2014-01-02T12:46:14.870

0

For what it's worth I had lots of trouble configuring vim to use the clipboard and wasn't able to get it to work until I reinstalled it via homebrew without the client-server option.

Jason Axelson

Posted 2013-12-19T03:36:00.413

Reputation: 1 390

0

http://vim.wikia.com/wiki/In_line_copy_and_paste_to_system_clipboard

put below settings in vimrc:

vnoremap \y y:call system("pbcopy", getreg("\""))<CR>
nnoremap \p :call setreg("\"", system("pbpaste"))<CR>p

noremap YY "+y<CR>
noremap P "+gP<CR>
noremap XX "+x<CR>

copy data in visual mode, paste data in normal mode.

hustljian

Posted 2013-12-19T03:36:00.413

Reputation: 111