Understand vim registers

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the vim category.

Last Updated: 2021-05-16

Call :reg to open up the registers list and see what text is available.

To copy a line to a specific register, say "c" write "cyy. I.e. the " signals that a register follows (c here).

Do not copy to a numbered register. This is simply a stack containing deleted lines.

To append to (instead of replacing a register), use capital letters: "Cyy

To paste from a named register, "cP

If the register consists of vim commands, you can execute it with @. E.g. if I yank the following text into a register b :help Gblame. Then @b will open up the help. In this way, macros are stored in registers.

Vim registers persist even after we close Vim. This means eventually, you may add some very convenient snippets or lines to a register, and use them in different text editing sessions. Or save up macros for reuse.