/lessons/2026-03-25
Registers: Vim's Hidden Clipboard System
Vim has 26+ named registers that act like individual clipboards. Master them and you'll never lose a yanked line again.
Most Vim users know y and p. Fewer know that every yank and delete operation writes to a register — and that you can control exactly which one.
The Register Landscape
Vim maintains several categories of registers:
"athrough"z— 26 named registers you control explicitly"0— the yank register (last yanked text, untouched by deletes)"1through"9— the delete history (a stack of your last 9 deletes)"+— the system clipboard"_— the black hole register (deletes without saving)".— the last inserted text"%— the current filename":— the last ex command
Using Named Registers
Prefix any yank or delete with "x where x is the register letter:
"ayy " yank current line into register a
"Ayy " append current line to register a (uppercase = append)
"ap " paste from register a
The uppercase trick is particularly powerful. Build up a collection of lines from different parts of a file by appending to the same register:
"ayy " first line into register a
jj
"Ayy " another line appended to a
5G
"Ayy " yet another line appended
"ap " paste all three lines together
The Yank Register Trick
Here's the scenario: you yank a line, then delete something to make room, then try to paste — but p pastes the deleted text, not the yanked line.
The fix: "0p. Register 0 always holds your last yank, unaffected by delete operations.
Pro Tip
Use :reg to see the contents of all registers at any time. Better yet, map it:
nnoremap <leader>r :registers<CR>
When you're refactoring, use named registers as staging areas. Yank the replacement text into "a, then navigate and use ciw followed by Ctrl-R a in insert mode to paste from register a without leaving insert mode.
Example
A real workflow for renaming a variable across a function:
" Yank the new name into register n
/newVariableName
"nyiw
" Now find each old name and replace
/oldVariableName
ciw<C-r>n<Esc>
" Repeat with n (find next) and . (repeat change)
n.n.n.
This is faster than a substitution command when you want to review each replacement individually.