How to make Vim yank to the OSX clipboard

Tagged clipboard, osx, vim, yank  Languages bash, vim

Add this to .vimrc:

set clipboard=unnamed

If you use Tmux you probably need this:

$ brew install reattach-to-user-namespace

Note, do NOT use something like this because it doesn’t work perfectly:

function! ClipboardYank()
  call system('pbcopy', @@)
function! ClipboardPaste()
  let @@ = system('pbpaste')

vnoremap <silent> y y:call ClipboardYank()<cr>
vnoremap <silent> d d:call ClipboardYank()<cr>
nnoremap <silent> p :call ClipboardPaste()<cr>p