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

How do I copy a line to another location without yanking?

Answer

:t {line-number}

Explanation

The :t (copy/transfer) command duplicates the current line and places it after the specified line number. It does not affect registers.

How it works

  • :t 0 copies the current line to the top of the file
  • :t $ copies it to the end
  • :t . duplicates the line below itself
  • :t -1 duplicates the line above itself

Example

:t 0     " Copy current line to top of file
:t .     " Duplicate current line
:5t 10   " Copy line 5 to after line 10

Tips

  • :t does not modify any registers (unlike yyp)
  • :'<,'>t $ copies a visual selection to end of file
  • :co is a synonym for :t
  • The source and destination can both use ranges and patterns
  • Use :t. to quickly duplicate the current line

Next

How do you yank a single word into a named register?