Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to yank from the command line

Tags:

vim

vi

I wonder if it is possible to yank something I have written in the command line from vim so I can later paste it again.

This would be particularly useful because I often try out search/replace patterns by just searching for them first and - if they match what I need - I would like to be able to just copy that searched expression from the command line and use it in my search/replace function.

I already know that you can paste into the command window by using <ctrl-r><buffer> and I just wonder if there is a command similar to this that will yank my whole command window.

like image 466
BergmannF Avatar asked Jan 18 '12 07:01

BergmannF


People also ask

How do you yank in bash?

ctrl-y. When you need the text again, simply do a yank ( ctrl-y ) and the shell will copy out the text in the cut buffer into the command line.

How do you yank?

Copying (Yanking) To copy text, place the cursor in the desired location and press the y key followed by the movement command. Below are some helpful yanking commands: yy - Yank (copy) the current line, including the newline character.

How do you yank text within Vi?

Copying text in Vim is also referred to as yanking. Use the y key on the keyboard when performing this operation. There are a number of yank commands, mainly differing on the amount of text you want to copy. Once in normal mode, move the cursor to the needed place and use the appropriate command.

How do I copy 5 lines from current cursor position?

Place the cursor on the line you wish to copy. Type yy to copy the line. Move the cursor to the place you wish to insert the copied line. Type p to insert the copied line after the current line on which the cursor is resting or type P to insert the copied line before the current line.


2 Answers

You can use the command line window. Use q+: to open it. Then you can navigate the window as an ordinary one and yank what you want to yank.

like image 59
lucapette Avatar answered Sep 30 '22 14:09

lucapette


Vim stores the most recently entered command in the : register and the most recently searched expression in the / register. Since you already know how to paste into the command window you can simply type <Ctrl-R>/ to paste in whatever you last searched for.

like image 34
David Brown Avatar answered Sep 30 '22 16:09

David Brown