Nvim Session 06: Registers Deep Dive
Vim has 48+ registers, not just one clipboard. Master them for powerful copy/paste workflows.
Pre-Session State
-
Use
yandpfor basic copy/paste -
Know about marks
-
Understand register types
-
Use system clipboard integration
Register Overview
| Register | Name | Purpose |
|---|---|---|
|
Unnamed |
Default for d/y/p |
|
Yank |
Last yank only (not delete!) |
|
Numbered |
Delete history (1=recent) |
|
Named |
User-controlled storage |
|
Append |
Append to named register |
|
System clipboard |
OS clipboard (ctrl+c/v) |
|
Selection |
X11 primary selection |
|
Black hole |
Discards (no register) |
|
Search |
Last search pattern |
|
Last insert |
Last inserted text |
|
Command |
Last ex command |
|
Filename |
Current filename |
|
Alternate |
Alternate filename |
Lesson 1: Unnamed and Yank Registers
Exercise 1.1: The unnamed register problem
Delete something:
dd " Delete line (goes to "")
yy " Yank line (goes to "" AND "0)
p " Pastes... the yank! Good.
dd " Delete another line
p " Pastes... the DELETE! Your yank is gone!
Problem: Deletes overwrite your yank in the unnamed register.
Exercise 1.2: The yank register solution
yy " Yank line → goes to "" AND "0
dd " Delete line → goes to "" only
"0p " Paste from yank register → original yank!
Rule: "0 always has your last YANK, never polluted by deletes.
Exercise 1.3: View registers
:reg " Show all registers
:reg 0 " Show just "0
:reg abc " Show a, b, c
Lesson 2: Named Registers
Concept: Store text in named locations, use them anytime.
Exercise 2.1: Yank to named register
"ayy " Yank line to register 'a'
"byiw " Yank inner word to register 'b'
"cyap " Yank around paragraph to 'c'
Paste from named:
"ap " Paste from register 'a'
"bp " Paste from register 'b'
Exercise 2.2: Delete to named register
"add " Delete line to register 'a'
"bdiw " Delete word to register 'b'
Later:
"ap " Paste deleted text from 'a'
Exercise 2.3: Append to register
Uppercase appends:
"ayy " Yank first line to 'a'
j
"Ayy " APPEND next line to 'a'
j
"Ayy " APPEND another line
"ap " Paste all three lines!
Exercise 2.4: Named register workflow
Collect snippets:
" Register 'h' for headers
/^## <CR>"hyy
" Register 'c' for code blocks
/```<CR>"cy}
" Register 'l' for links
/\[.*\]<CR>"lyW
Lesson 3: System Clipboard
Exercise 3.1: Clipboard register
Copy to system clipboard:
"+yy " Yank line to system clipboard
"+yiw " Yank word to clipboard
"+yap " Yank paragraph to clipboard
Paste from system clipboard:
"+p " Paste from clipboard
"+P " Paste before cursor
Exercise 3.2: Check clipboard support
:echo has('clipboard') " Should return 1
:checkhealth " Check clipboard provider
Exercise 3.3: Clipboard keymaps (common setup)
In your config:
-- In domus-nvim/lua/domus/config/keymaps.lua
vim.keymap.set({"n", "v"}, "<leader>y", [["+y]], { desc = "Yank to clipboard" })
vim.keymap.set("n", "<leader>Y", [["+Y]], { desc = "Yank line to clipboard" })
vim.keymap.set({"n", "v"}, "<leader>p", [["+p]], { desc = "Paste from clipboard" })
Exercise 3.4: Selection register (X11)
On Linux:
- "+ = CLIPBOARD (Ctrl+C/V)
- "* = PRIMARY (middle-click paste)
"*yy " Yank to primary selection
"*p " Paste from primary selection
Lesson 4: Special Registers
Exercise 4.1: Black hole register
Delete without affecting registers:
"_dd " Delete line, gone forever
"_diw " Delete word, doesn't overwrite ""
Use case: Delete junk without losing your clipboard content.
Exercise 4.2: Read-only registers
"%p " Paste current filename
"#p " Paste alternate filename
".p " Paste last inserted text
":p " Paste last ex command
"/p " Paste last search pattern
Exercise 4.3: Expression register
"=5*5<CR>p " Insert 25
"=strftime('%Y-%m-%d')<CR>p " Insert date
"=system('hostname')<CR>p " Insert hostname
In insert mode:
Ctrl-r =5+5<CR> " Insert 10
Ctrl-r =expand('%')<CR> " Insert filename
Lesson 5: Numbered Registers (Delete History)
Exercise 5.1: Understanding numbered registers
dd " → goes to "1
dd " → "1 moves to "2, new delete to "1
dd " → "2→"3, "1→"2, new→"1
"1p " Paste most recent delete
"2p " Paste second most recent
"3p " etc.
Exercise 5.2: Walking through delete history
After pasting from numbered:
"1p " Paste "1
u " Undo
. " Repeat with "2 automatically!
u. " Undo and paste "3
u. " Continue through history
Lesson 6: Practical Patterns
Exercise 6.1: Multiple clipboard workflow
" Collect different pieces
"ayy " Line to 'a'
j
"byy " Next line to 'b'
" Navigate to destination
"bp " Paste 'b'
"ap " Paste 'a' (still there!)
Exercise 6.2: Infrastructure config editing
Copying between files:
" In source file
"hyiw " Yank hostname to 'h'
f=w"iyW " Yank IP to 'i'
" In destination file
"hp " Paste hostname
"ip " Paste IP
Exercise 6.3: Copy to clipboard for external use
" Copy command for documentation
"+yy " Yank line to clipboard
" Paste into Slack/Teams/Wiki
Exercise 6.4: Record macro to register
Macros use same registers!
qa " Record macro to register 'a'
...
q " Stop recording
"ap " Paste the macro as text! (see the keys)
" Edit the text
"ayy " Yank edited text back to 'a'
@a " Play the modified macro
Summary: Register Quick Reference
| Register | Access |
|---|---|
Unnamed |
|
Yank |
|
Named |
|
Clipboard |
|
Selection |
|
Black hole |
|
Filename |
|
Expression |
|
Common Workflows
| Task | Commands |
|---|---|
Yank for later use |
|
Copy to clipboard |
|
Delete without overwriting |
|
Paste original after delete |
|
Insert calculation |
|
Exercises to Complete
-
[ ] Yank to
"a, delete something, paste with"ap(survives delete) -
[ ] Yank to
"0, delete multiple lines, paste with"0p -
[ ] Copy to system clipboard with
"+y, paste in another app -
[ ] Delete with
"_d, verify""unchanged with:reg -
[ ] Use expression register to insert a calculation
Next Session
Session 07: Visual Mode Mastery - Selection power.
Session Log
| Timestamp | Notes |
|---|---|
Start |
<Record when you started> |
End |
<Record when you finished> |
Discoveries |
<What surprised you?> |