Visual Studio : short cut Key : Duplicate Line
Visual Studio : short cut Key : Duplicate Line
Visual Studio : short cut Key : Duplicate Line
Re: Visual Studio : short cut Key : Duplicate Line
In Visual Studio 2022
Ctrl + E, V
In Visual Studio 2019
Ctrl + D
In Visual Studio 2017 (v15.6 and after)
Ctrl + D
In Visual Studio 2017 (pre v15.6)
(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:
[](https://i.sstatic.net/4Mfkb.png)
See [this reference](https://dailydotnettips.com/did-you-know-now-you-can-duplicate-line-of-code-without-loosing-your-clipboard-content-within-visual-studio/) for more information.
Pre VS2017, built-in method using clipboard
As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.
Ctrl + C will copy the line if nothing is selected.
Macro solution (pre VS2017)
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 Module
```
To 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
*(Réponse tronquée)*
Ctrl + E, V
In Visual Studio 2019
Ctrl + D
In Visual Studio 2017 (v15.6 and after)
Ctrl + D
In Visual Studio 2017 (pre v15.6)
(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:
[](https://i.sstatic.net/4Mfkb.png)
See [this reference](https://dailydotnettips.com/did-you-know-now-you-can-duplicate-line-of-code-without-loosing-your-clipboard-content-within-visual-studio/) for more information.
Pre VS2017, built-in method using clipboard
As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.
Ctrl + C will copy the line if nothing is selected.
Macro solution (pre VS2017)
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 Module
```
To 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
*(Réponse tronquée)*