Tip 29Duplicate or Move Lines Using ‘:t’ and ‘:m’ Commands

The :copy command (and its shorthand :t) lets us duplicate one or more lines from one part of the document to another, while the :move command lets us place them somewhere else in the document.

For demonstration purposes, we’ll use this shopping list:

 Shopping list
  Hardware Store
  Buy new hammer
  Beauty Parlor
  Buy nail polish remover
  Buy nails

Duplicate Lines with the ‘:t’ Command

Our shopping list is incomplete: we also need to buy nails at the hardware store. To fix the list, we’ll reuse the last line of the file, creating a copy of it below “Hardware Store.” We can easily do so using the :copy Ex command:

KeystrokesBuffer Contents

{start} ...

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.