Visual Studio : short cut Key : Duplicate Line
Is there a shortcut for Duplicate Line command in Visual Studio 2008?
Some similar examples:
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
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:
Duplicate line command for Visual Studio
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 assing a keyboard shortcut to it:
And that's it. Enjoy!
There's a free extension you can download here that lets you duplicate lines without replacing the clipboard contents.
By default its bound to Alt + D, but you can change it to anything you want by going to Tools->Options->Environment->Keyboard. Type "Duplicate" in the search box and look for "Edit.DuplicateSelection" and edit the shortcut to whatever you want. I prefer Ctrl + D to be consistent with other editors.
It's simple Ctrl + C ; Ctrl + V , check this link. As long as you don't select any text, this will duplicate the line the cursor is over when you press Ctrl+C.
链接地址: http://www.djcxy.com/p/8676.html