How to Duplicate a Line in VS Code, Notepad++, Sublime and Vim

Duplicate a line in your editor — Every shortcut, and the three that take a count

The duplicate-line shortcut is Shift+Alt+Down in VS Code, Ctrl+D in Notepad++, and Ctrl+Shift+D in Sublime Text. Each one makes exactly one copy per press, so ten copies means ten presses. Three editors do better than that and accept a count: Vim takes 100p, Notepad++ has a Run a Macro Multiple Times dialog, and Emacs 29 takes a prefix argument on duplicate-line.

That split — one-press-one-copy versus name-a-number — is the whole subject. Everything below is either a shortcut or a way of avoiding pressing it repeatedly.

The duplicate-line shortcut in each editor

Duplicate the current line, by editor
EditorWindows / LinuxmacOSCommand name
VS CodeShift+Alt+DownShift+Option+DownCopy Line Down
Notepad++Ctrl+DDuplicate Current Line
Sublime TextCtrl+Shift+DCmd+Shift+DDuplicate Line
Vimyy then pyy then pyank and put
Emacs 29+M-x duplicate-lineM-x duplicate-lineduplicate-line

VS Code's version does not touch the clipboard, so whatever you copied earlier survives. Notepad++ has no macOS build, which is why that cell is empty. Emacs only gained a built-in duplicate-line in version 29 — before that it was C-a C-k C-k C-y C-y or a custom function.

The three that accept a number

Holding a shortcut down is fine for three copies and absurd for three hundred. These are the ways to state the count instead.

Vim: put the number in front

Vim's count prefix applies to almost every command, and putting it in front of a paste repeats the paste. Yank the line once, then paste it as many times as you want:

yy then 100p

That gives 100 copies in six keystrokes with no macro and no plugin. The same prefix works in insert mode for a literal string — 100i, then ab, then Esc types ab a hundred times, which is the closest thing any editor has to a repeat function.

Notepad++: record a macro, then give it a count

Notepad++ is the only one of these with a dialog built for exactly this.

  1. Put the text on a line and copy it.
  2. Go to Macro, then Start Recording.
  3. Paste once.
  4. Go to Macro, then Stop Recording.
  5. Go to Macro, then Run a Macro Multiple Times, and enter your number.

The same dialog offers to run until the end of the file, which is useful when the operation is a transformation of existing lines rather than a repetition of one.

Emacs: a prefix argument

In Emacs 29 and later, duplicate-line respects the universal argument, so C-u 5 M-x duplicate-line produces five copies. For a keyboard macro the same idea applies: record with F3 and F4, then run it a hundred times with C-u 100 F4.

Multi-cursor is a different tool

Multiple cursors get suggested for this constantly, and they solve the opposite problem. They are for making one edit in many places, not many copies of one thing.

Adding cursors, by editor
EditorCursor belowAt every match
VS CodeCtrl+Alt+DownCtrl+Shift+L
Sublime TextCtrl+Alt+DownAlt+F3
Notepad++Ctrl+Alt+ClickColumn mode with Alt+Drag

If the lines already exist and you want to change all of them, this is the right tool. If the lines do not exist yet, adding cursors does not create them.

What none of them do

Three limitations are shared across every editor on this page, and they are the reason people end up looking for something else.

If the repetition belongs inside a program rather than in your editor, the one-line expression for it exists in every language — see how to repeat a string N times in code.

Need an exact count, or copies on one line? Set the text, the number and the separator, then paste the finished block back into your editor.

Open the text repeater

Frequently asked questions

How do you duplicate a line in VS Code?

Press Shift+Alt+Down on Windows and Linux, or Shift+Option+Down on macOS. The command is Copy Line Down, and it does not use the clipboard, so anything you copied earlier is preserved. Each press makes one copy.

How do you duplicate a line in Notepad++?

Press Ctrl+D, which runs Duplicate Current Line. For a specific number of copies, record a macro that pastes once, then use Macro then Run a Macro Multiple Times and enter the count.

How do you repeat a line 100 times in Vim?

Yank the line with yy, then type 100p. Vim's count prefix repeats the paste, so this produces 100 copies without a macro or a plugin. In insert mode the same prefix works on typed text: 100i, then the text, then Esc.

Can you duplicate a line multiple times in one command?

In Vim and in Emacs 29 or later, yes: Vim takes a count prefix such as 100p, and Emacs accepts a universal argument such as C-u 5 M-x duplicate-line. VS Code and Sublime Text have no count, so each copy is a separate press unless you record a macro.

Is multi-cursor the same as duplicating a line?

No. Multiple cursors apply one edit across lines that already exist, using Ctrl+Alt+Down in VS Code and Sublime Text. They do not create new lines, so they cannot produce copies of a line that is not there yet.

How do you put repeated copies on one line instead of separate lines?

No duplicate-line command does this, because each duplicate goes onto its own line. Either join the lines afterwards with a Find and Replace on the newline character, or generate the repeated text with a separator already between the copies and paste it in.

← All articles