How do I copy a specific line by number to after the current line?
Answer
:5t.
Explanation
The :t ex command (also spelled :copy) copies a range of lines to a target address without touching any register. :5t. copies line 5 to just after the current line (.). Unlike yank-and-put, this operation leaves the unnamed register and your clipboard completely intact — an essential property when you are mid-edit and cannot afford to lose a yanked selection.
How it works
:{source}t{dest}— copy line(s) at{source}to after{dest}:5t.— copy line 5 to after the current line- The destination
.always means the current line;0means before line 1 (the very top);$means after the last line - Both source and destination support all Ex address forms: absolute line numbers,
.,$, marks ('a), and relative offsets
Example
You're editing line 42 and want to duplicate the boilerplate function signature from line 8 without disturbing your yank register:
:8t.
Line 8 is now copied just below line 42. Your cursor stays at the copy, your registers are untouched.
Tips
:-5t.— copy the line 5 rows above to here (relative addressing):'a,'bt$— copy the range from markato markbto the end of the file:t.(no source address) — duplicate the current line in-place, equivalent toyypbut register-safe:5,10t25— copy lines 5–10 to after line 25:mis the move equivalent: it deletes the source and pastes it at the destination