Visual Studio : short cut Key : Duplicate Line

后端 未结 30 1402
[愿得一人]
[愿得一人] 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:12

    If you like eclipse style line (or block) duplicating using CTRL+ALT+UP or CTRL+UP+DOWN, below I post macros for this purpose:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports System.Diagnostics
    
    Public Module DuplicateLineModule
        Sub DuplicateLineDown()
            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
    
            lineNumber = selection.TopLine
            line = selection.Text
    
            selection.MoveToDisplayColumn(selection.BottomLine, 0)
            selection.EndOfLine()
            selection.Insert(vbNewLine & line)
        End Sub
        Sub DuplicateLineUp()
            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
    
            lineNumber = selection.BottomLine
            line = selection.Text
    
            selection.MoveToDisplayColumn(selection.BottomLine, 0)
            selection.Insert(vbNewLine & line)
            selection.MoveToDisplayColumn(lineNumber, 0)
        End Sub
    End Module
    

提交回复
热议问题