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

How do I duplicate the current line to the end of the file without yanking or moving the cursor?

Answer

:.t$

Explanation

The Ex command :.t$ copies the current line to the very end of the file. It uses the :t (copy) command — an alias for :copy — with . as the source address (current line) and $ as the destination (last line). The cursor stays where it is.

How it works

  • : enters the command line
  • . is the address for the current line
  • t (or co / copy) is the copy command
  • $ means "after the last line of the file"

The general form is :[range]t {dest}, where range specifies what to copy and dest is where to place the copy.

Example

Given a file:

foo
bar
baz

With the cursor on foo, running :.t$ produces:

foo
bar
baz
foo

Tips

  • Copy multiple lines: :.,.+3t$ copies the current line plus the next 3 lines to the end
  • Copy to a specific line: :.t5 copies the current line after line 5
  • Use a range: :5,10t$ copies lines 5–10 to the end of the file
  • Move instead of copy: replace t with m:.m$ moves the current line to the end
  • This avoids touching the yank registers, so your clipboard is unaffected

Next

How do I open the directory containing the current file in netrw from within Vim?