Visual Studio : short cut Key : Duplicate Line

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

    Here's a macro based on the one in the link posted by Wael, but improved in the following areas:

    • slightly shorter
    • slightly faster
    • comments :)
    • behaves for lines starting with "///"
    • can be undone with a single undo
    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    
    Public Module Module1
    
        Sub DuplicateLine()
            Dim sel As TextSelection = DTE.ActiveDocument.Selection
            sel.StartOfLine(0) '' move to start
            sel.EndOfLine(True) '' select to end
            Dim line As String = sel.Text
            sel.EndOfLine(False) '' move to end
            sel.Insert(ControlChars.NewLine + line, vsInsertFlags.vsInsertFlagsCollapseToEnd)
        End Sub
    
    End Module
    

提交回复
热议问题