Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy text from commandline mode in Vim while searching

Tags:

vim

There is already a question regarding how to copy text in commandline in Vim. There are two alternative answers:

  1. ":p, and
  2. Ctrl+F, followed by finding the previous command.

But 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?

like image 878
Mert Nuhoglu Avatar asked Sep 28 '11 14:09

Mert Nuhoglu


People also ask

How do I copy text from vim?

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.


1 Answers

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
like image 125
Peter Rincker Avatar answered Sep 27 '22 22:09

Peter Rincker