Registers let you keep several clipboards, recover overwritten yanks and exchange text with other apps.
Every yank and delete goes into a register. Prefix a command with " and a register name to choose which: "ayy yanks a line into register a, "ap puts it.
The important registers:
""the unnamed register, used by plainp. Every yank and delete writes it."0holds the last yank only. Deletes do not touch it, so afteryiwthendd,"0pstill pastes the yanked word."1..."9hold recent linewise or multi-line deletes, shifting down each time; small deletes go to"-."a..."zare yours. An uppercase name appends:"Ayyadds the line toa."+is the system clipboard and"*the primary selection on X11 (both need Vim built with+clipboard; check:version)."_is the black hole:"_dddeletes without clobbering anything.- Read-only:
".last inserted text,"%file name,":last command line,"/last search.
In Insert mode and on the command line, Ctrl-r followed by a register name inserts its contents: Ctrl-r 0 pastes the last yank, Ctrl-r / the last search pattern. :reg (or :reg a 0) shows what is stored.
Macros, covered next, are stored in these same registers, which means you can edit a macro as text.
Example
"ayiw " yank word into register a
"Ayiw " append another word to a
"ap " put register a
yiw " yank a word...
dd " ...then delete a line (unnamed register now holds the line)
"0p " still pastes the yanked word
"_dd " delete without touching any register
"+yy " copy line to the system clipboard
:reg a 0 + " inspect registersRemember
- "0 = last yank, "1-"9 = recent deletes, "a-"z = yours
- Uppercase register name appends instead of overwriting
- "+ is the system clipboard; "_ discards
Watch out for
- Expecting "+ to work in a Vim built without clipboard support; check :version for +clipboard.