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

How do I duplicate the current line and place the copy directly below it?

Answer

:t.

Explanation

The :t (short for :copy) command copies lines from one location to another. The dot (.) is Vim's shorthand for the current line. So :t. reads as "copy the current line to just after the current line" — an instant, single-command line duplication.

How it works

  • :t is the copy command (also written as :co); it takes a destination address
  • . means the current line (both as the source range and as the destination)
  • :t. therefore copies line N and inserts the copy after line N, leaving the cursor on the new copy
  • A count range lets you duplicate multiple lines: :1,3t. copies lines 1–3 below the current line
  • You can target any line number as the destination: :t$ copies the current line to the end of the file

Example

Before:

const BASE_URL = 'https://api.example.com';

After :t.:

const BASE_URL = 'https://api.example.com';
const BASE_URL = 'https://api.example.com';

The cursor lands on the new duplicate, ready for editing.

Tips

  • Compare with yyp (yank line + paste below): :t. is preferred because it does not overwrite a register, leaving your clipboard intact
  • Visual selection + :t. duplicates the selected block: select lines with V, then :'<,'>t.
  • :m. (the move command) works identically but moves the line instead of copying it

Next

How do I visually select a double-quoted string including the quotes themselves?