How to use registers in Vim
"ayy"0p"_dVim keeps copied and deleted text in registers. Type " and a letter before a command to choose one: "ayy copies the line into register a, and "ap puts it.
Without a name, y, d and p use the unnamed register, which every copy and delete replaces. Your last copy also stays in register 0, so "0p puts it even after a delete.
Worked example
Copy the title into register a, delete the old line, then put the title from a.
The dd replaced the unnamed register, but register a still held the title.
Commands
- "ayy
- Copy the line into register
a. - "ap
- Put from register
a. - "Ayy
- Add the line to the end of register
a. - "0p
- Put your last copy, even after deletes.
- "_dd
- Delete without touching any register.
Exceptions
- A lowercase name replaces the register. An uppercase name adds to it.
- Macros are kept in registers too. qa records into
a, so "ap puts the keys you recorded as text. - Registers live inside Vim. The system clipboard is the
+register, and it only works if your Vim was built with clipboard support.