views:

86

answers:

3

does Visual Studio 2010 not have a "join lines" keyboard shortcut?

EDIT - That is when on line X anywhere, I hit a shortcut key once, and then line X+1 joins to line X (eliminating CR between them so to speak)

A: 

What do you mean? Deleting at lines' beginning/end will join two lines. What are you thinking of doing?

Graham Perks
That is when on line X anywhere, I hit a shortcut key once, and then line X+1 joins to line X (eliminating CR between them so to speak)
Greg
@Greg- It appears your three identical comments need to be merged not joined. :-)
Ray Vega
+1  A: 

As I far as I know it does not.

However, you can create and save a new VS macro using the following code:

Sub JoinLines()
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ExecuteCommand("Edit.Delete")
    DTE.ActiveDocument.Selection.EndOfLine()
End Sub

and assign a keyboard shortcut to it (like CTRL + j)

This code will join the current line with the one right below it.

Ray Vega
I think he wants to join with the line below it, meaning that you can probably eliminate the first 2 lines of the macro.
Gabe
You're right. Thanks. Now fixed.
Ray Vega
Assuming he's asking because he's a vim user, you'd actually want: EndOfLine, delete, insert a space (I think), move left one character.
Noah Richards
this looks good - just stuck trying to figure out in VS2010 how to do the keyboard assignment to the JoinLines Sub method...
Greg
@Greg- `Tools -> Options -> Environment -> Keyboard`. In text field for `Show commands containing:`, simply type `JoinLines` and your new macro should display. Then in `Press shortcut keys`, type `Ctrl + j`, click `Assign`, and finally `OK`. It should work after that.
Ray Vega
got it - great - thanks
Greg
A: 

If you want the join feature to act like Vim (pressing Shift-J) then use this macro that joins, inserts space and places cursor after the space:

Sub JoinLines()
    Dim textSelection As TextSelection = DTE.ActiveDocument.Selection
    With textSelection
        .EndOfLine()
        .Insert(" ")
        .Delete(1)
    End With
End Sub

Just assign it to something like ALT-J (as CTRL-J and CTRL-SHIFT-J are taken)

Piers Myers