vimtricks.wiki Concise Vim tricks, one at a time.

How do I store different pieces of text in separate registers for later pasting?

Answer

"ayy "byy "cyy

Explanation

How it works

Vim provides 26 named registers (a through z) that you can use as independent clipboards. Each register holds its own text independently, so you can store up to 26 different pieces of text simultaneously.

To yank into a named register, prefix any yank command with " followed by the register letter:

  • "ayy -- yank the current line into register a
  • "byiw -- yank the inner word into register b
  • "cy$ -- yank from cursor to end of line into register c

To paste from a specific register:

  • "ap -- paste from register a after the cursor
  • "bP -- paste from register b before the cursor

Named registers persist until you explicitly overwrite them (or close Vim without viminfo). This makes them ideal for assembling text from different locations.

Example

Suppose you are building an email from pieces scattered across a document:

  1. Navigate to the greeting and yank it: "ayy (stores in register a)
  2. Navigate to the main body paragraph and yank it: "b3yy (stores 3 lines in register b)
  3. Navigate to the signature and yank it: "cyy (stores in register c)
  4. Move to your target location
  5. Paste them in order: "ap then "bp then "cp

You can verify what each register holds at any time by typing :registers abc to see just those three registers. This multi-register workflow is much more efficient than repeatedly copying and pasting one item at a time.

Next

How do you yank a single word into a named register?