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
)
Copying to clipboard using register '+' or '*' is not working?
Reason: Your particular version of vim was compiled without clipboard support.Type vim --verion on console and you will see -xterm_clipboard. Installing vim with gui packages solves this issue. On ubuntu you can do this by typing on shell:
sudo apt-get install vim-gui-common
Now again do vim --version on console. Most probably, you would be seeing +xterm_clipboard now!!
So, now you can copy anything to clipboard using register + (like "+yy to copy current line to clipboard)
For MacVim and Windows Gvim, simply add the following to your ~/.vimrc
:
set clipboard=unnamed
Now all operations such as yy
, D
, and P
work with the clipboard. No need to prefix them with "*
or "+
.
Fakeclip implements the +
and *
buffers if they aren't natively supported.
My main problem was the default OSX version of Vim. Installing it via homebrew added +clipboard
to the build.
You can check with:
vim --version
to see if it says -clipboard
or +clipboard
.
if you have the +clipboard
option on your Vim installation (you can check with :version
) and you are in visual mode you can do "+y
This will yank the selection to the buffer +
that is the clipboard.
I have added the following maps to my vimrc and it works fine.
vmap <leader>y "+y
: With this I can do leader key
follow by y
to copy to the clipboard in visual mode.
nmap <leader>p "+p
: With this I can do leader key
follow by p
to paste from the clipboard on normal mode.
PD : On Ubuntu I had to install vim-gtk to get the +clipboard
option.
For Ubuntu users, the package you want to retrieve for using the clipboard is vim-full. The other packages (vim-tiny, vim) do not include the clipboard feature.