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,autoselectEDIT:
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!
54 Answers
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 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:
:.!pbcopyto copy lines 1 to 50
:1,50!pbcopyTo copy the contents of the clipboard into the current vim bufer use:
:r !pbpaste 4 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.
1For 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.