How do I yank and paste using named registers?
Answer
"ayy ... "ap
Explanation
Named registers let you store multiple pieces of text independently. Use "a before a yank or delete command to store text in register a, then "ap to paste it later.
How it works
"atells Vim to use registerafor the next operationyyyanks the current line"ayyyanks the current line into registera"appastes the contents of registera
Vim has 26 named registers (a through z), so you can store up to 26 different pieces of text simultaneously.
Example
- On line 1, type
"ayyto yank line 1 into registera - On line 5, type
"byyto yank line 5 into registerb - Move to your target location
- Type
"apto paste from registera - Type
"bpto paste from registerb
Tips
- Use uppercase to append:
"Ayyappends to registerainstead of overwriting - Use
:registersor:regto see the contents of all registers - The
"(unnamed) register always holds the last yank or delete - The
0register always holds the last yank specifically (not deletes)