Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Duplicate Line (Ctrl+D) & Duplicate File/FolderNew to Visual Studio Code? Get it now.
Duplicate Line (Ctrl+D) & Duplicate File/Folder

Duplicate Line (Ctrl+D) & Duplicate File/Folder

Zlatko Bratkovic

|
1 install
| (0) | Free
Duplicate the current line or selection with Ctrl+D, and duplicate files/folders from the Explorer.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Duplicate Line (Ctrl+D)

Press Ctrl+D (Cmd+D on macOS) in the editor:

  • No selection – the current line is duplicated below, and the cursor moves to the copy.
  • Text selected – the selection is duplicated right after itself, and the copy is selected.
  • Works with multiple cursors.

This overrides the default Ctrl+D ("Add Selection to Next Find Match"). To keep that, see Keyboard shortcuts.

Duplicate file / folder

Right-click a file or folder in the Explorer and choose Duplicate File or Duplicate Folder. You are asked for the new name. A free name such as name copy.ext is suggested. The copy goes in the same folder, and a duplicated file opens in the editor. If you select several items, each one is copied with an automatic name and you are not asked.

Keyboard shortcuts

Command Command ID Default key
Duplicate Line or Selection duplicateLine.duplicate Ctrl+D (Cmd+D on macOS)
Duplicate File duplicateLine.duplicateFile none
Duplicate Folder duplicateLine.duplicateFolder none

Change a shortcut in the Keyboard Shortcuts editor

  1. Open Keyboard Shortcuts: press Ctrl+K Ctrl+S, or use File → Preferences → Keyboard Shortcuts.
  2. Search for duplicateLine.
  3. Double-click a command, press the keys you want, then press Enter.

Change a shortcut in keybindings.json

Open the Command Palette (Ctrl+Shift+P), run Preferences: Open Keyboard Shortcuts (JSON), and add entries:

[
  // Turn off the extension's Ctrl+D (the leading "-" removes a binding)
  { "key": "ctrl+d", "command": "-duplicateLine.duplicate" },

  // Use a different key to duplicate the line or selection
  { "key": "ctrl+shift+d", "command": "duplicateLine.duplicate",
    "when": "editorTextFocus && !editorReadonly" },

  // Optional: give Ctrl+D back to "Add Selection to Next Find Match"
  { "key": "ctrl+d", "command": "editor.action.addSelectionToNextFindMatch",
    "when": "editorFocus" },

  // Optional: shortcuts for duplicating files and folders
  { "key": "ctrl+alt+d", "command": "duplicateLine.duplicateFile",
    "when": "filesExplorerFocus && !explorerResourceIsFolder" },
  { "key": "ctrl+alt+d", "command": "duplicateLine.duplicateFolder",
    "when": "filesExplorerFocus && explorerResourceIsFolder" }
]

Your own shortcuts always win over the extension's, and updating the extension does not undo them. If nothing is selected in the Explorer, Duplicate File works on the file that is open in the editor.

Compatibility

This extension needs VS Code 1.60 or newer (August 2021), or an editor built on it. It uses only standard VS Code APIs, so it runs the same way in each of these editors:

Editor Supported versions
VS Code 1.60 and newer: Windows, macOS, Linux, and Remote (SSH / WSL / Containers)
code-server 3.12 and newer (these use VS Code 1.60 or newer)
VSCodium, OpenVSCode Server Any version based on VS Code 1.60 or newer

Build

npm install
npm run package        # -> duplicate-line-0.2.0.vsix

Install

Editor How
VS Code code --install-extension duplicate-line-0.2.0.vsix
Windsurf (Codeium) windsurf --install-extension duplicate-line-0.2.0.vsix, or Extensions view → ... → Install from VSIX...
code-server code-server --install-extension duplicate-line-0.2.0.vsix, or upload the file and use Extensions → ... → Install from VSIX...

Develop

Open this folder in VS Code and press F5 to launch an Extension Development Host.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft