How to copy yanked text to VI command prompt

Vim

Vim Problem Overview


I want to know if there is any way by which I can paste yanked text to the command window. For instance if I have yanked a word and I want to grep it in some location I can't simply paste the word using 'p'. However if I copy it to clipboard, Shift-Insert will paste the same thing.

Is there any tweak available which would allow me to paste yanked text to the vim command prompt?

I am using gvim on Windows.

Vim Solutions


Solution 1 - Vim

try to use

<ctrl+r>"

where " stands for default register.

Solution 2 - Vim

<C-R>" Will paste default buffer. Alternately, you can use q: to open a buffer for the next command. try :help q:

Solution 3 - Vim

  • ensure first you are in normal mode by pressing Esc
  • once in normal mode, press :
  • then use the keyboard combination ctrl-r, and then type "

Note: if you are yanking a full line containing relative file path, the line feed will by pasted as well ... i.e. :! touch src/bash/script.sh^M

WILL create a "funny file path" containing the "\r" if you do not remove the last ^M ...

Solution 4 - Vim

To save you a step of yanking, if your cursor is on the word you want to use in Ex, use:

 <ctl-r><ctl-w>

This eschews yanking to paste into the command line; instead, one pastes the word under one's cursor directly onto the command line. E.g.:

:%s/<ctl-r><ctl-w>/foo/g

Solution 5 - Vim

If it is just a word that you want to copy, you can use <C-r><C-w>

  1. Put your cursor over the word
  2. Then you can type something like :vim <C-r><C-w> *

Solution 6 - Vim

You can yank to the clipboard using the * named buffer. For instance, this will copy the current line to the clipboard:

"*yy

So you can copy a line using this, and then paste it with shift-insert in the commandline.

Similarly, you can paste from the clipboard like this:

"*p

Solution 7 - Vim

The clipboard's +, on Mac at least. So you'd write "+yy to yank a line to the clipboard, and "+p to paste. Though you could always use Command-C and Command-V.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCanopusView Question on Stackoverflow
Solution 1 - VimMykola GolubyevView Answer on Stackoverflow
Solution 2 - VimsoulmergeView Answer on Stackoverflow
Solution 3 - VimRookView Answer on Stackoverflow
Solution 4 - VimgregoryView Answer on Stackoverflow
Solution 5 - VimSysCoderView Answer on Stackoverflow
Solution 6 - VimNathan FellmanView Answer on Stackoverflow
Solution 7 - VimABCView Answer on Stackoverflow