views:

515

answers:

4

Hi , after a lot of search , I really want to fix this.. "Is there a Short Cut Key for Duplicate Line exists in Visual Studio 2008 "?

Duplicate Line i.e. like Ctrl+j in Edit Plus or Crtl+D in Notepad++

+1  A: 

Look at this link, you need to create macro to create the shortcut... Duplicate line command for Visual Studio

Wael Dalloul
+1  A: 

It's simple CTRL-C + CTRL-V , check this link.

cand
There are numerous occasions where you don't want to go through the clip board, for example if you want to duplicate a line and then replace some content in it with something you have in the clip board.
Effata
Sure, but the question asked for a shortcut, not for a general solution for text editing, so I think that for simple purposes it's enough (at least it was in my case).
cand
@cand, thanks, but I was expecting something like Ctrl+j in Edit Plus or Crtl+D in Notepad++ ... is there any in VS2008 or in VS2010
openidsujoy
I've only found this one. However it's not that bad - of course easier would be to use ctrl+D, but if You want to duplicate 1 line in 100 copies You can do it using ctrl+c (without need to select anything, just put command prompt over wanted line) + 100 times ctrl+v. It's only one set of keystrokes more than ctrl+d solution. It can be more problematic if You want to do more complex duplication.
cand
+1  A: 

If you like eclipse style line (or block) duplicating using CTRL+ATL+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
Lolo
great stuff, thanks!
Peter Perháč
A: 

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
Peter Perháč