Solaris Advanced User's Guide

Copying Lines

Copying a line requires two commands: yy or Y (“yank”) and either p (“put below”) or P (“put above”). Note that Y does the same thing as yy.

To yank one line, follow these steps.

  1. Position the cursor anywhere on the line you want to yank.

  2. Type yy.

  3. Move the cursor to the line above where you want to put (copy) the yanked line.

  4. Type p.

    A copy of the yanked line appears in a new line below the cursor.

    To place the yanked line in a new line above the cursor, type P.

The yy command works well with a count: to yank 11 lines, for example, type 11yy. Eleven lines, counting down from the cursor, are yanked, and vi indicates this with a message at the bottom of the screen: 11 lines yanked.

You can also use the P or p commands immediately after any of the deletion commands discussed earlier. This action puts the text you deleted above or below the cursor, respectively.

Caution – Caution –

Use only cursor-moving commands between yanking or deleting and putting. If you delete or yank any other text before putting the new text in place, the lines you yanked or deleted are lost.