How do I understand which register Vim uses for each operation?
Answer
:help registers
Explanation
Vim has 10 types of registers, each serving a specific purpose. Understanding which register receives text from each operation is the key to mastering Vim's clipboard system.
Register hierarchy
| Type | Register | Filled by |
|---|---|---|
| Unnamed | "" |
Every yank, delete, change, substitute |
| Yank | "0 |
Only y commands |
| Numbered | "1-"9 |
Line-or-more deletes (history queue) |
| Small delete | "- |
Less-than-a-line deletes |
| Named | "a-"z |
Only when you specify them explicitly |
| Black hole | "_ |
Sends text into the void |
| Expression | "= |
Evaluates Vimscript expressions |
| Read-only | "., "%, ":, "# |
Auto-filled by Vim |
| Selection | "*, "+ |
System clipboard / primary selection |
| Last search | "/ |
Auto-filled by search commands |
What happens when you yank
yiw " Text goes to: "", "0
What happens when you delete a line
dd " Text goes to: "", "1 (old "1→"2, "2→"3, etc.)
What happens when you delete a word
dw " Text goes to: "", "-
What happens with named registers
"ayy " Text goes to: "", "0, "a
"Add " Text APPENDS to "a, also goes to "", "1
Viewing registers
:reg " Show all non-empty registers
:reg abc " Show specific registers
:reg 0123 " Show yank and numbered registers
Tips
- Always use
"0pwhen you want to paste yanked text after a delete - Named registers (
"a-"z) are the only ones you fully control - Uppercase named registers (
"A-"Z) append instead of overwriting - The unnamed register
""points to the last used register — it's an alias, not a separate store - Master this hierarchy and you'll never lose clipboard text again