Copying text in vim to the global clipboard

On my linux computer I am able to copy text to the clipboard with the command "+y. How do I do the same on Mac?


macOS version of vim is compiled with -clipboard (you can check with vim --version). So there's no shared clipboard available. In this case you can download/recompile new vim or you can use system command pbcopy (man page). Here's how to use it as CTRL ⌃+C shortcut:

map <C-c> y:e ~/clipsongzboard<CR>P:w !pbcopy<CR><CR>:bdelete!<CR>

Add this to your ~/.vimrc file.

Explanation of this command can be found here: vimtips @ quora


Additionally you can install the program MacVim, which is a version of Vim 8 compiled for Mac, including a GUI. However you don't need the GUI, you can just link the mvim executable to vim somewhere on your $PATH, and the + register will work as your clipboard just like you are used to.

MacVim is also recommended if you are going to install some recent plugins like YouCompleteMe.