Canopus
Canopus

Reputation: 7457

How to copy yanked text to VI command prompt

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.

Upvotes: 125

Views: 43569

Answers (7)

Rook
Rook

Reputation: 62588

  • 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 ...

Upvotes: 23

gregory
gregory

Reputation: 13023

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

Upvotes: 16

soulmerge
soulmerge

Reputation: 75774

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

Upvotes: 44

SysCoder
SysCoder

Reputation: 784

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> *

Upvotes: 5

ABC
ABC

Reputation: 21

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.

Upvotes: 2

Nathan Fellman
Nathan Fellman

Reputation: 127628

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

Upvotes: 2

Mykola Golubyev
Mykola Golubyev

Reputation: 59932

try to use

<ctrl+r>"

where " stands for default register.

Upvotes: 188

Related Questions