Alexander Abakumov
Alexander Abakumov

Reputation: 14539

Automatically remove spaces when joining two lines into the one

In Visual Studio Code, when pressing the Delete button at the end of a current line:

            []<- a currsor is here
        )

, a text on a next line obviously jumps to the current line and it becomes something like this:

            []                )

So we have a bunch of spaces in the joined text (between square brackets and paranthesis in the example above), so we have to delete them manually.

In the "big" Visual Studio (maybe because of ReSharper) all those spaces get deleted automatically and immediately, with a single Delete stroke, we have what we wanted to do:

            [])

How can we remove those spaces with Visual Studio Code automatically? Is there a setting for this?

Upvotes: 4

Views: 3245

Answers (2)

Mark
Mark

Reputation: 181319

Actually, while making a macro to do what you wanted, I see that Ctrl+Delete does exactly what you want when at the end of a line.

If you wanted to only use the Delete key and nothing else, you will need an extension of some kind. A macro could do the job but it sounds like you want the Delete key to work differently within a line of code than from at the very end. Something a macro would not be able to distinguish. An extension could do that.

But I suggest just use the simple Ctrl+Delete.

Upvotes: 3

Scott McPeak
Scott McPeak

Reputation: 12769

I'm fairly sure there is not a command or setting like this built in to VSCode.

  • It is always difficult to prove a negative. I looked at all the keys and settings with "delete" and "backspace" (as you probably did too) and came up empty. I've also made a number of excursions into the source and github issues for various reasons, and have a sense for the level of sophistication of what is implemented in VSCode; this is beyond what VSCode tends to have.

However, there is an extension called Hungry Delete that does something similar, although not quite what you've asked for. I suggest trying to modify it; I doubt it would be difficult. Whatever logic you come up with can be bound to Delete, supplanting the usual behavior.

Of course, if you haven't written an extension before, start with the (quick) tutorial first.

Upvotes: 2

Related Questions