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 such and interacting with the system clipboard like using "+". Apparently this doesn't work in this case because 1) you shouldn't install unncessary software to the target machine and 2) whatever copied to the target machine's clipboard won't be available on the host machine. The first thing that would cross your mind is to use Ctrl+Shift+C` but that doesn’t always work.

In this kind of situation, you can just 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.

If you prefer a command line approach, you should set up tmux

Twitter, Facebook