Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: insert selected text into command line?

Tags:

vim

If I've selected some text in visual mode, how do I insert the selected text into the command line?

For example, if I want to search for the currently selected text, I could use y/<c-r>"… But is there some way of doing it without first yanking the selected text?

Edit: A better example, as searching while in visual mode would expand the selection: if I've got part of a file name selected, and I want append to that name then open it in a new editor.

like image 767
David Wolever Avatar asked Feb 02 '11 19:02

David Wolever


People also ask

How do I paste into vim command prompt?

Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do I select a chunk of text in vim?

Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.

How do you paste text into yanked?

Yes. Hit Ctrl - R then " . If you have literal control characters in what you have yanked, use Ctrl - R , Ctrl - O , " .


1 Answers

I have remapped : in visual mode to solve this problem. With following mapping I can paste selected text to the command line and b - onus - move the cursor to the leftmost position:

vnoremap : y:<C-r>"<C-b>

One small drawback I can see - pressing : now cancels the selection.

like image 131
grwlf Avatar answered Sep 21 '22 21:09

grwlf