<t>In Visual Studio 2022<br/>
<br/>
Ctrl + E, V<br/>
<br/>
In Visual Studio 2019<br/>
<br/>
Ctrl + D<br/>
<br/>
In Visual Studio 2017 (v15.6 and after)<br/>
<br/>
Ctrl + D<br/>
<br/>
In Visual Studio 2017 (pre v15.6)<br/>
<br/>
(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:<br/>
<br/>
<br/>
<br/>
See this reference for more information.<br/>
<br/>
Pre VS2017, built-in method using clipboard<br/>
<br/>
As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.<br/>
<br/>
Ctrl + C will copy the line if nothing is selected.<br/>
<br/>
Macro solution (pre VS2017)<br/>
<br/>
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:<br/>
<br/>
Visual Basic:<br/>
<br/>
`Imports System<br/>
Imports EnvDTE<br/>
Imports EnvDTE80<br/>
Imports System.Diagnostics<br/>
<br/>
Public Module DuplicateLastLineModule<br/>
Sub DuplicateLine()<br/>
Dim line As String<br/>
DTE.ActiveDocument.Selection.StartOfLine(0)<br/>
DTE.ActiveDocument.Selection.EndOfLine(True)<br/>
line = DTE.ActiveDocument.Selection.Text<br/>
DTE.ActiveDocument.Selection.EndOfLine()<br/>
DTE.ActiveDocument.Selection.NewLine()<br/>
DTE.ActiveDocument.Selection.StartOfLine(0)<br/>
DTE.ActiveDocument.Selection.Text = line<br/>
End Sub<br/>
End Module<br/>
<br/>
<br/>
To create the macro, just go to the macro explorer<br/>
("Tools->Macros->Macro Explorer" or Alt+F8) and copy paste the code in<br/>
a new module. Now just assign a keyboard shortcut to it:<br/>
<br/>
- go to Tools->Options...<br/>
<br/>
- under Environment, click Keyboard<br/>
<br/>
- in the "Show Commands Containing" textbox, enter "duplicate" (this according to the name you gave the module.)<br/>
<br/>
- you should now see the macro in the list below<br/>
<br/>
- choose "Text Editor" from the "Use new shortcut in" list<br/>
<br/>
- set focus in the "Press shortcut keys" textbox and<br/>
<br/>
*(Réponse tronquée)*</t>