How do I view the contents of all registers in Vim?
Answer
:registers
Explanation
The :registers command displays the contents of all Vim registers, showing you exactly what text is stored in each one. This is essential for managing yanked and deleted text, especially when working with named registers.
How it works
:registers(or:regfor short) opens a list of all registers and their contents- Each register is identified by a single character:
"(unnamed),0-9(numbered),a-z(named), and several special registers - The display shows the register name, its type (character, line, or block), and the stored text
Key registers explained
""— the unnamed register, filled byy,d,c,s, andx"0— the yank register, filled only byycommands (not deletes)"1-"9— numbered registers, a history of recent deletes (1 is most recent)"a-"z— named registers, explicitly set by the user with commands like"ayy"+— the system clipboard register"*— the primary selection register (X11 systems)"/— the last search pattern".— the last inserted text":— the last Ex command"%— the current file name
Example
After yanking a line with yy and deleting a word with dw, running :reg might show:
"" some word
"0 The full yanked line
"1 some word
"% main.go
Tips
- Use
:reg a b cto view only specific registers instead of all of them - Use
"0pto paste from the yank register when the unnamed register has been overwritten by a delete - In insert mode, press
<C-r>followed by a register name to insert its contents - Use
:reg +to quickly check what is on your system clipboard