Quick Copy & Paste Techniques for Default vi/vim: Moving Text In and Out During Pentesting

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 pentesting, 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, if not they explain how to use the yank and paste commands, which only work inside vi/vim.

However, you don’t have 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.

Note that this methods only works if you use a X11 (or newer ones like Wayland) based terminal. If your local machine somehow doesn’t support GUI at all, you can’t easily copy and paste. This is highly unlikely though because there’s no practical reason to use such a setup for pentesting today.

Twitter, Facebook