How you actually copy&paste in vi/vim

Jun Takemura · September 15, 2024

Vim is highly customizable and you can do almost anything if you put an effort into it. But the thing is if you’re into hacking, you sometimes encouter an occasion where you can only use the default vim or vi. And if you look up ‘how to copy and paste in vim’, so many forums would show up where people tell you how to install gvim and use the system clipboard.

However, you’re not supposed to use the system clipboard in vim if you just wanna copy&paste some text. Instead you should select texts and middle click. Historically vi/vim have been used on linux and old linux didn’t use the windows-like copy&paste function, but they used primary selection. This is the feature where you can just select the text (using a mouse or the visual mode) and the text is automatically copied to the primary buffer. You can paste the content in the primary buffer by middle-clicking.

Modern linux distros offer both primary selection and the system clipboard. When the middle click button doesn’t work for some reason, you can press the left and right click buttons simultaneously.

Twitter, Facebook