There is already a question regarding how to copy text in commandline in Vim. There are two alternative answers:
":p
, andBut these methods don't work when the previous command is a search. That is if I enter into command mode with /
or ?
, then the search term used cannot be accessed with these methods.
Is there a way to copy text for search text as well?
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. Go to any external application and CMD + v to paste.
I believe you are looking for the /
register. You can use "/p
to paste the last search. While on the command-line you can use <c-r>
followed by a register to insert the contents of the given register. example: <c-r>/
will paste the last search.
You may also wish to use q/
to do more extensive editing of your previous searches.
:h registers
:h q/
:h c_CTRL-R
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