Quick Tip – Copying From Vim

This issue drove me insane. The answer was crazy simple so I figured I’d throw it out there.

I found that I could copy and paste anywhere in X without an issue (this uses the clipboard buffer). I could also select text and middle click to paste without issue (this uses the primary buffer. I could also select and paste with the mouse in URXVT. Within Vim, I could also copy by selecting and paste (when in insert mode) with a middle click. What I couldn’t do was select text in Vim and middle click to paste it anywhere else.

Further, I could confirm that the data wasn’t hitting the primary buffer upon selection using xsel -op to dump the primary buffer.

After a good while of searching (which came after more time than should have been spent diagnosing the exact issue) I found this thread, which described my issue and the solution.

The answer is that the mouse=a directive in my vimrc that makes visual mode work with the mouse is also keeping it from selecting text in the way that’s needed to drop it into the primary buffer (to copy it). Disabling this setting fixes the copy issue, but also turns off visual mode with the mouse, which I’d like to keep.

The workaround was to hold shift while selecting text I want to copy, which keeps it from entering visual mode and allows the copy to happen.