Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy yanked text to VI command prompt

Tags:

vim

People also ask

How do I paste a yanked line in vi?

After you have selected the wanted text you can press: y to yank (copy) the content. d to delete (cut) the content. p to put (paste) the content.

How do I paste a yanked line in Vim to Notepad?

In Vim, Copying is done using the y or "yanking". To copy selected text to system clipboard type "+y in Normal Mode. Now you can paste it anywhere else using Ctrl-v .


try to use

<ctrl+r>"

where " stands for default register.


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


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


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

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

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