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)
On macos 10.8, vim is compiled with -clipboard so to use "*y you'll need to
recompile. Luckily brew install vim would compile a new version easily for you
and it will be +clipboard.
What worked for me in my .vimrc
set clipboard=unnamed
if has("unnamedplus") " X11 support
set clipboard+=unnamedplus
endif
In my case I just had to do :
:set mouse=v
please visit the original solution on superuser.com
You can visually select text and type :w !pbcopy<CR>
Or you can include the below key mappings in your ~/.vimrc file. They cut/copy text in visual mode to the operating system's clipboard.
vmap <C-x> :!pbcopy<CR>
vmap <C-c> :w !pbcopy<CR><CR>
source: http://drydevelopment.com/blog/vim-pbcopy-on-os-x
If you are on MacOS X:
$ brew install vim
$ vim --version
VIM - Vi IMproved 7.4 [...]
Then, add to your .vimrc:
set clipboard=unnamed
Now you just need to be in vim and do :%y, to have all the content copied to your clipboard.
I am currently on OS X 10.9 and my efforts to compile vim with +xterm_clipboard brought me nothing. So my current solution is to use MacVim in terminal mode with option set clipboard=unnamed in my ~/.vimrc file. Works perfect for me.