Visual Studio : short cut Key : Duplicate Line

后端 未结 30 1306
[愿得一人]
[愿得一人] 2020-12-12 10:01

Is there a shortcut for Duplicate Line command in Visual Studio 2008?

Some similar examples:

  • in
相关标签:
30条回答
  • 2020-12-12 10:05

    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.

    0 讨论(0)
  • 2020-12-12 10:05

    As I can't use Macros in my Visual Studio 2013 I found a Visual Studio Plugin (I use it in 2012 and 2013). Duplicate Selection duplicates selections and whole Lines - they only need to be partial selected. The standard shortcut is ALT + D.

    0 讨论(0)
  • 2020-12-12 10:05

    For those still viewing this question on Visual Studio post-2008, a real Edit.Duplicate has been added:

    • CTRL+E, V
    • CTRL+D (VS 2017 15.6+)
    0 讨论(0)
  • 2020-12-12 10:06

    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.

    0 讨论(0)
  • 2020-12-12 10:08

    Ctrl + C + V works for me on VS2012 with no extension.

    0 讨论(0)
  • 2020-12-12 10:08

    Not an answer, just a useful addition: As a freebie, I just invented (well... ehm... adjusted the code posted by Lolo) a RemoveLineOrBlock macro. Enjoy!

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    
    Public Module RemoveLineOrBlock
    
        Sub RemoveLineOrBlock()
            Dim selection As TextSelection = DTE.ActiveDocument.Selection
            Dim lineNumber As Integer
            Dim line As String
    
            If selection.IsEmpty Then
                selection.StartOfLine(0)
                selection.EndOfLine(True)
            Else
                Dim top As Integer = selection.TopLine
                Dim bottom As Integer = selection.BottomLine
    
                selection.MoveToDisplayColumn(top, 0)
                selection.StartOfLine(0)
    
                selection.MoveToDisplayColumn(bottom, 0, True)
                selection.EndOfLine(True)
            End If
    
            selection.LineDown(True)
            selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn,True)
    
            selection.Delete()
    
            selection.MoveToDisplayColumn(selection.BottomLine, 0)
            selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
    
        End Sub
    
    End Module
    
    0 讨论(0)
提交回复
热议问题