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
)
You can use MacVim when you're on a Mac to easily access the clipboard using the standard OS keys.
It's also fully backward compatible with normal Vim, so I don't even have to have a separate .vimrc
.
Command-c works for me in both MacVim and in the terminal.
on mac when anything else seems to work - select with mouse, right click choose copy. uff
Shift cmd c – set copy mode Drag mouse, select text, cmd c to copy selected text Cmd v to paste
I used:
map <C-x> :!pbcopy<CR>
vmap <C-c> :w !pbcopy<CR><CR>
It worked really well.
Use Homebrew's vim: brew install vim
Mac (as of 10.10.3 Yosemite) comes pre-installed with a system vim that does not have the clipboard
flag enabled.
You can either compile vim for yourself and enable that flag, or simply use Homebrew's vim which is setup properly.
To see this for yourself, check out the stock system vim with /usr/bin/vim --version
You'll see something like:
$ /usr/bin/vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Nov 5 2014 21:00:28)
Compiled by root@apple.com
Normal version without GUI. Features included (+) or not (-):
... -clientserver -clipboard +cmdline_compl ...
Note the -clipboard
With homebrew's vim you instead get
$ /usr/local/bin/vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled May 10 2015 14:04:42)
MacOS X (unix) version
Included patches: 1-712
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
... +clipboard ...
Note the +clipboard