Skip to content

Lesson 4 of 9 · 23m

Registers and the Clipboard You Cannot See

Vim's multiple clipboards: yank, delete history, named registers, system clipboard, black hole, and the expression register.

The first time you delete a line and lose the text you copied thirty seconds earlier, you have met registers. Vim does not have one clipboard; it has dozens. This is not trivia — it changes how confidently you rearrange code.

Yanks and deletes are separate streams

"0   last yank
"1–"9 delete history, newest large deletes first

Copy a function name with yiw, then delete an old block with dd. Plain p now pastes the deleted block, not the copied name — but "0p still pastes the yank. This is the single most useful register fact in daily work.

Deletes feed a rotating history. Small deletions behave differently from large or linewise deletions, so do not build critical workflows on remembering which numbered register contains what. Use :registers and look.

Named registers are deliberate storage

"ayy   yank current line into register a
"ap    paste register a
"Ayy   append current line to register a

Lowercase overwrites; uppercase appends. That append behavior is ideal for collecting scattered lines: walk a file, append matches into register a, then paste the assembled result into a scratch buffer.

The system clipboard is a register too

"+   system clipboard
"*   primary selection on X11 (often absent or different on Wayland)
"+y  yank selection to system clipboard
"+p  paste from system clipboard

Many Neovim builds can talk to the system clipboard only through a provider such as xclip, xsel, wl-copy, or platform-native tooling. If "+ does nothing, run :checkhealth provider before reinstalling everything.

A common convenience setting is vim.opt.clipboard:append("unnamedplus"), which makes ordinary yanks use the system clipboard. It also means destructive deletes can clobber what other applications expect, so senior operators often prefer explicit "+.

Registers beyond copying

"%   current file name
"/   last search pattern
":   last Ex command
".   last inserted text
"_   black hole — discard instead of storing
"=   expression register

The black hole matters: "_dd deletes a line without touching any paste source. Use it when pruning noise around text you still intend to paste.

The expression register evaluates Vimscript or Lua-exposed expressions. In insert mode, Ctrl-r =strftime('%Y-%m-%d') inserts today's date. In normal editing, Ctrl-r inserts register contents while already in insert mode.

Field notes

  • :registers (or :reg) is not cheating. Inspect before pasting something important.
  • Use "_ for deletion you never want to see again; otherwise your delete history fills with noise.
  • Ctrl-r in insert mode inserts a register literally; Ctrl-r Ctrl-r inserts it more literally, avoiding some abbreviation/trigger surprises.
  • Clipboard integration fails most often in SSH, tmux, and container environments. Treat it as a transport problem, not a Vim problem.

Was this lesson helpful?

Sign in to rate