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

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 vs yyp (3), but :t . doesn't touch any register
  • :t accepts marks: :'at 'b copies the line at mark a to below mark b
  • Combine with :g: :%g/TODO/t $ copies all TODO lines to the end of the file
  • :t is dot-repeatable via @: — repeat the last Ex command

Next

How do I run a search and replace only within a visually selected region?