Copying and pasting between the clipboard and vim has always been a nightmare for me. You find a big chunk of code you want to copy over to your project, tab over to vim, get into insert mode, and hit Command + v. What do you get? A big wall of text that has every line tabbed over. Definitely not the format you were trying to copy over.
1 2 3 4 5 |
|
The easiest fix for this is to set the paste mode before you head into insert the code:
1
|
|
You’ll notice the statusline shows you in PASTE
mode and the tooltip shows -- INSERT (paste) --
. Paste in your code and things should be good. When you’re done, revert back with:
1
|
|
Another option is to set your pastetoggle key.
1
|
|
The above code will set the F2 key to toggle between paste and nopaste.
What I REALLY want is a way to yy and pp from my system clipboard and have it work in vim. One large problem with this is that the methods that OS X uses to go to and from the clipboard (pbcopy and pbpaste) break when you work in tmux sessions.
To fix this, we need to install reattach-to-user-namespace
from ChrisJohnsen/tmux-MacOSX-pasteboard. We can install this threw brew:
1
|
|
and in our .vimrc, add the following line:
1
|
|
Now, anything you yank from vim is available in the clipboard, and anything in the clipboard is available to paste in vim!