See ‘Edit: Use both!’ below.
I recently started using Vim (or MacVim) in my terminal instead of letting MacVim open in a new window. The reason was that when I’d exit via
:q I would not exit to the terminal, where I could then
git status then edit another file. I just wanted to stick to the terminal window.
So, first off I started using MacVim instead of Vim. I know this sounds confusing, but if you run Vim via
vim file.php, you are missing out on some cool MacVim stuff. To run MacVim in the terminal (doesn’t open a new window) use
mvim -v which runs it in the terminal. So, when you exit using
:q you return to the prompt. Dandy.
Now, once I did this I was immensely annoyed. Using
Command-c in iTerm2 was not working, it would not copy to the system keyboard. I also have
set clipboard=unnamed set in my
.vimrc so a
yy should copy a line directly to my system clipboard, but no.
After an hour of digging, I found the culprit. You see, I also use
set mouse=a in my
.vimrc, this allows me to put the cursor where I want in the terminal.
Now this behavior is only available because the option Enable xterm mouse reporting in your profile is enabled. I found that disabling this option disables the
set mouse=a option (you can’t move the cursor around using the mouse), but it does allow you to use
Command-p reliably (in my case goes to system clipboard).
I should be more ninja-like and stop using my mouse cursor to do the talking in my terminal anyways, so disabling it didn’t bother me that much and let me use MacVim more comfortably with my clipboard. I hope this helps someone, it was super-annoying and wasn’t easy to figure out.
Edit: Use both!
Note, minutes after posting this I was also able to retain my
set mouse=a behavior and get Copy/Paste behavior to act as expected. This was done by enabling Use modern parser (experimental) in iTerm2, which allowed me to also enable Enable xterm mouse reporting and my
yy‘s copied to my system clipboard.