Vim course Lesson 5 of 6

Vim from zero: a register holds what you yanked

A yank copies text into a register. "ayi" on item latte = "oat" copies oat. "ap puts that note at the cursor. The register is the clipboard you can name.

Zoe is one of GoByte's characters. This post was drafted by AI agents in Zoe's voice, then fact checked, run and edited by the GoByte team.

Back to top

y copies. The text goes into a register, which is a named slot. The default slot is the unnamed register, and it is also where deletes go, so a later dd overwrites your yank. A named register, "a through "z, keeps the text until you overwrite that name. The note inside the quotes is the text worth keeping.

A register is a named slot of text#

y copies a span into a register. The unnamed register also receives deletes, so a later dd overwrites a yank you meant to keep. "a names a slot that deletes will not touch. "ayi" yanks the inside of the quotes into register a. On item latte = "oat", that text is oat, and the line does not change. "ap puts the slot back at the cursor, which is how the same milk lands on the next drink. :registers shows the slots. "0 holds the most recent yank even after a delete has replaced the unnamed register.

The yank stores the note. The line stays
  1. register atextoat
"ayi"
oat

The quote names the register#

On item latte = "oat", with the cursor inside the quotes, "ayi" yanks oat into register a. The line does not change. "ap puts the contents of a at the cursor. The sample's second block is what register a holds: oat.

yi" without the a yanks the same note into the unnamed register instead. "0p puts the most recent yank even after a delete has overwritten the unnamed register. "0 is worth remembering the first time a paste comes out as the line you deleted rather than the note you copied.

Look at a register before you blame the put#

:registers lists them. a should show oat after "ayi". If it shows an older yank, the cursor was not inside the quotes you thought, or a later command wrote "a again. Registers are just slots of text. The next lesson applies one change to every order line, which is the dot command across the file.

Report a mistake

Your product here? Partner with us

Back to top

Discussion

No comments yet. Signed in GoByte members with a verified e-mail can join. Community guidelines

Reading is open to everyone. Commenting and voting need a GoByte account with a verified e-mail.