Copying and pasting with registers
You can copy text by using the y (yank) command, followed by a movement or a text object. You can also hit y from a visual mode when you have selected some text.
Tip
In addition to all of the standard movement, you can use yy to yank the contents of the current line.
Let’s yank the following piece of code by typing ye (yank until the end of the word):
Figure 2.35 – ye will yank (copy) has_spam
into the default register.
This will copy has_spam
into our default register. Now, place the cursor where you want the text to appear (the text is inserted after the cursor):
Figure 2.36 – Place cursor before the position where you want to insert the text.
To paste the code, hit p:
Figure 2.37 – p will insert the default register contents after the cursor.
The delete and change operators also yank content so that you can paste it later...