I have an area selected in Vim. How can I copy it into the OS X clipboard?
(The OS X clipboard can be written to via a pipe to /usr/bin/pbcopy
)
I meet the same issue, after install macvim
still not working, finally I found a way to solve:
Try to uninstall all vim first,
brew uninstall macvim
brew uninstall --force vim
and reinstall macvim
brew install macvim --with-override-system-vim
Then you can use "*y
or "+y
, don't have to set clipboard=unnamed
If the clipboard is enabled, you can copy a selected region to the clipboard by hitting "*y
To see if it is enabled, run vim --version
and look for +clipboard
or -clipboard
. For example, it's not enabled by default on my 10.5.6 box:
% which vim /usr/bin/vim % vim --version VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Nov 11 2008 17:20:43) Included patches: 1-22 Compiled by _www@b77.apple.com Normal version without GUI. Features included (+) or not (-): ... -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments ...
If it had been compiled with +clipboard
, I'd be able to use the "*
register to access the system clipboard.
I downloaded the 7.2 source and compiled it (easy as tar xjf vim-7.2.tar.bz && cd vim72 && ./configure && make && sudo make install
), and the clipboard was enabled:
% which vim /usr/local/bin/vim % vim --version VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Mar 24 2009 17:31:52) Compiled by rampion@Myrrhy.local Normal version with GTK2 GUI. Features included (+) or not (-): ... +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments ...
However, even after compiling, I couldn't copy to the clipboard when running vim in Terminal.app, only in X11.app.
If your Vim is not compiled with clipboards, you wish to copy selected text instead of entire lines, you do not want to install MacVim or other GUI, the simplest solution is to add this line to your .vimrc:
map <C-c> y:e ~/clipsongzboard<CR>P:w !pbcopy<CR><CR>:bdelete!<CR>
To use it, simply visually select the text you want to copy, and then Control-C. If you want a full explanation of this line read "How to Copy to clipboard on vim".
For Mac - Holding option
key followed by ctrl V
while selecting the text did the trick.
Depending on which version of Vim I use, I'm able to use the +
register to access the clipboard.
"Mac OS X clipboard sharing" may have some ideas that work for you as well.
command-C? This at least works for the vim launched from within Terminal.app for text selected with mouse.