How do I copy lines from elsewhere in the file to the current cursor position?
Answer
:{range}copy . or :t
Explanation
:copy (abbreviated :t) copies a range of lines to a target address. :t . copies to just below the current line — effectively duplicating lines from anywhere in the file to where your cursor is, without yanking or navigating.
Syntax
:{range}copy {address}
:{range}t {address}
{range}— which lines to copy (source){address}— where to put them (destination).means the current line
Examples
Copy line 10 to below the current line:
:10t .
Copy lines 5–15 to below the current line:
:5,15t .
Copy the current line to below itself (duplicate):
:t .
This is the fastest way to duplicate a line — shorter than yyp.
Copy line 20 to the end of the file:
:20t $
Copy the last visual selection:
:'<,'>t .
:copy vs :move
| Command | Effect |
|---|---|
:t / :copy |
Copies lines (originals remain) |
:m / :move |
Moves lines (originals are removed) |
Tips
:t .to duplicate the current line is a Vim golf favorite — 4 keystrokes vsyyp(3), but:t .doesn't touch any register:taccepts marks::'at 'bcopies the line at markato below markb- Combine with
:g::%g/TODO/t $copies all TODO lines to the end of the file :tis dot-repeatable via@:— repeat the last Ex command