I'm trying to copy text from my vim search term. I spend a fair bit of time building regular expressions for sed search&replace. Since my regex is often quite complicated, I like to build it up in a search before executing :%s/regex/new text/g
In a terminal vim, I can copy my new regex from the search line using the mouse. I'd like to use gvim as much as possible, but it doesn't let right mouse clicks through for me to copy.
Any ideas how to get the search term into a buffer?
Thanks,
Andrew
In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard.
To copy text from outside applications into Vim editor, first copy the text using the usual Ctrl-C command then go to Vim editor and type "+p in Normal Mode. I find the above commands very tedious to type every time I copy-paste from outside Vim, so I mapped the Ctrl-y to copy and the Ctrl-p to paste in Vim.
In command mode (where you are when you hit : in normal mode), you can do ctrl-R /
, which will expand to your last search term (other ctrl-R favorites are " for your yank buffer, or % for the full path of the current window)
You actually don't need to do that though. If you leave out the search term for :s, it will assume you want to use the last thing you searched for. so you can /searchregex, and then right after do :%s//replaceregex/ and it will use search regex to do the replace.
Use q:
to open an editable window containing your commandline history. From there you can use all your usual Vim toolset to copy/paste/etc.
For the equivalent feature regarding search history, type q/
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With