Greg
Greg

Reputation: 34818

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

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)

Upvotes: 21

Views: 7411

Answers (7)

gawkface
gawkface

Reputation: 2322

Microsoft Visual Studio Professional 2019 (am on Version 16.8.4) now has a shortcut inbuilt yayy!
It's shift+alt+ L & then shift+alt+ J
I remember the shortcut thinking of Lines(L) - Join(J) (it could have been J ... L but ah well, grouping i think)
This is available in Menu Edit -> Advanced -> Join lines

Upvotes: 2

Nigel Scott
Nigel Scott

Reputation: 693

I had been using CodeMaid for this, but it is very slow with large files. To replicate CodeMaid's behaviour with a macro, I've combined Ray Vega's and javs' solutions into the following:

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

Note: As macros have been dropped in VS2013, I'm using the Visual Commander extension, so the macro actually looks more like:

Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
  Implements VisualCommanderExt.ICommand

  Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ExecuteCommand("Edit.WordDeleteToEnd")
    DTE.ActiveDocument.Selection.Insert(" ")
  End Sub
End Class

Upvotes: 1

javs
javs

Reputation: 808

This is not exactly what you want, but I find it useful nonetheless.

If you are at the end of the first line, press Ctrl+Del to join the next line and delete any white space between them.

You still have to be at the end of the line, but this will work on virtually every editor, without any modifications.

Upvotes: 19

Brian Liedtke
Brian Liedtke

Reputation: 9

Try the End and then the Delete key sequence.

End moves to the end of the line and the Delete key removes the EOL after the cursor.

Upvotes: 0

Piers Myers
Piers Myers

Reputation: 10917

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).

Upvotes: 2

thumbmunkeys
thumbmunkeys

Reputation: 20764

I use the CodeMaid extension for this, it provides a Ctrl + M Ctrl + J shortcut to join lines (and some other useful things too)

Upvotes: 16

Ray
Ray

Reputation: 192406

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.

Upvotes: 5

Related Questions