Is there a shortcut for Duplicate Line command in Visual Studio 2008?
Some similar examples:
Is there a shortcut for Duplicate Line command in Visual Studio 2008?
Some similar examples:
Ctrl + E, V
Ctrl + D
Ctrl + D
(edit) This feature is now built-in in VS2017: Ctrl + E, V duplicates a line if nothing is selected, or duplicates selection. You can assign it to a different key combination, or find it in the menu:
See this reference for more information.
As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.
Ctrl + C will copy the line if nothing is selected.
If you'd like to implement a more complete solution, perhaps to create a simpler keyboard shortcut or you don't want to effect the clipboard, see this guide:
Visual Basic:
Imports System Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Public Module DuplicateLastLineModule Sub DuplicateLine() Dim line As String DTE.ActiveDocument.Selection.StartOfLine(0) DTE.ActiveDocument.Selection.EndOfLine(True) line = DTE.ActiveDocument.Selection.Text DTE.ActiveDocument.Selection.EndOfLine() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.StartOfLine(0) DTE.ActiveDocument.Selection.Text = line End Sub End ModuleTo create the macro, just go to the macro explorer ("Tools->Macros->Macro Explorer" or Alt+F8) and copy paste the code in a new module. Now just assign a keyboard shortcut to it:
- go to Tools->Options...
- under Environment, click Keyboard
- in the "Show Commands Containing" textbox, enter "duplicate" (this according to the name you gave the module.)
- you should now see the macro in the list below
- choose "Text Editor" from the "Use new shortcut in" list
- set focus in the "Press shortcut keys" textbox and hit the combination on the keyboard you wish to use for it (Ctrl+Shift+D in my case)
- hit the "Assign" button
- you should now see the shortcut in the "Shortcuts for selected command" textbox
- hit the OK button
And that's it. Enjoy!
In Visual studio 2017 and maybe other version No need Macro or Extension,
Tools > Options > Environment > Keyboards Show commands containing: write Edit.DuplicatePress shortcut keys: and press Ctrl + D and click Assign buttonOK to save your new keyboard shortcutfor Visual Studio 2012, 2013, 2015, 2017 follow the link and download the extension
https://marketplace.visualstudio.com/items?itemName=ctlajoie.DuplicateSelection
Now go into Tools > Options > Keyboard, and type "Duplicate" in the search box (the full command string is "Edit.DuplicateSelection"). Here you can bind it to any shortcut in the same way you would for any other command.
For those still viewing this question on Visual Studio post-2008, a real Edit.Duplicate has been added:
For Visual Studio Code 2019:
Edit menu keyboard shortcuts with: ctrl+k and ctrl+s
Edit "Copy Line Down" (Shift + Alt + DownArrow) to your your own shortcut.
You can find it, with the command ID: editor.action.copyLinesDownAction
For me, It's ctrl+d
Ctrl + D is a new shortcut introduced in VS 2017 v15.6 that seems to do the exact thing that Ctrl + E, V
Ctrl + D will duplicate the line the cursor is in and insert it right below the line in focus. If you’d like to duplicate a specific set of code, simply select the portion of code you want to duplicate before invoking the duplicate code command.
It won't affect your clipboard
http://www.jetbrains.com/resharper/
My story: started working in a new company, never used Visual Studio before. One of the first things - how to duplicate line. After setting up macro ReSharper told me: would you like to substitute my shortcut which was: "duplicate text" :)
in VS2019 and also in VS2017 you can select Tools->Options->Keyboard and you can choose in the scheme drop-down Resharper (Visual Studio) option, and you will get a mapping like if you were using Resharper, in this case Ctrl + D will do the trick for duplicating the line. Anyways, based on the documentation this should be out of the gate in Visual Studio 2017 Version 15.8 or greater
On Linux Mint, you can do; Ctrl + Alt + Shift + 2 => Duplicate up Ctrl + Alt + Shift + 8 => Duplicate down
Visual Studio Code : May 2020 (version 1.46) Shift + UpArrow/DownArrow : To Duplicate the line of code