How do I store different pieces of text in separate registers for later pasting?
Answer
"ayy "byy "cyy
Explanation
How it works
Vim provides 26 named registers (a through z) that you can use as independent clipboards. Each register holds its own text independently, so you can store up to 26 different pieces of text simultaneously.
To yank into a named register, prefix any yank command with " followed by the register letter:
"ayy-- yank the current line into registera"byiw-- yank the inner word into registerb"cy$-- yank from cursor to end of line into registerc
To paste from a specific register:
"ap-- paste from registeraafter the cursor"bP-- paste from registerbbefore the cursor
Named registers persist until you explicitly overwrite them (or close Vim without viminfo). This makes them ideal for assembling text from different locations.
Example
Suppose you are building an email from pieces scattered across a document:
- Navigate to the greeting and yank it:
"ayy(stores in registera) - Navigate to the main body paragraph and yank it:
"b3yy(stores 3 lines in registerb) - Navigate to the signature and yank it:
"cyy(stores in registerc) - Move to your target location
- Paste them in order:
"apthen"bpthen"cp
You can verify what each register holds at any time by typing :registers abc to see just those three registers. This multi-register workflow is much more efficient than repeatedly copying and pasting one item at a time.