Floating Sunfish
Floating Sunfish

Reputation: 5720

Visual Studio Code Does Not Comment-out Empty Lines

Visual Studio Code Does Not Comment-out Empty Lines


I've searched everywhere for a solution to this issue but couldn't find anything, and it's been bugging me for months now.

Basically what happens is that VS Code ignores empty lines when you tell it to comment out multiple lines of code.

So for example, let's say I highlighted all the code below and told VS Code to comment it out:

package com.mycompany.app;

public class MyApp {
    public static void main(String[] args) {
        SayHello();
    }

    static void SayHello() {
        System.out.println("Hello!");
    }
}

What I expected to get:

// package com.mycompany.app;
// 
// public class MyApp {
//     public static void main(String[] args) {
//         SayHello();
//     }
// 
//     static void SayHello() {
//         System.out.println("Hello!");
//     }
// }

What I got instead:

// package com.mycompany.app;

// public class MyApp {
//     public static void main(String[] args) {
//         SayHello();
//     }

//     static void SayHello() {
//         System.out.println("Hello!");
//     }
// }

I've only experienced this with Java and Golang so far, but I assume this happens for all other languages inside VS Code too.

The reason I want my comments to stay connected to each other is so I know which lines I commented out together in case I need to uncomment them back.

I am also aware of the Shift + Alt + A shortcut, but that typically uses Block Comments (which I don't like using), and I only want Line Comments.

Is there a setting I'm missing? Because I tried searching within VS Code and couldn't find anything either.

Any help would be greatly appreciated.

Upvotes: 15

Views: 2242

Answers (3)

Floating Sunfish
Floating Sunfish

Reputation: 5720

A new VS Code setting has been added that resolves this issue:

"editor.comments.ignoreEmptyLines": false

Unfortunately, it is only tagged as "insiders-released" despite being included in Stable versions of VS Code.

Hopefully, this issue gets addressed in future versions.

Upvotes: 4

Mark
Mark

Reputation: 180667

An option to have empty lines commented out is coming to v1.48. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_48.md#thank-you and https://github.com/microsoft/vscode/pull/93160

New setting:

Editor > Comments: Ignore Empty Lines default is true (will ignore)

[editor.comments.includeEmptyLines]

In Insiders' Build already v1.48.

Upvotes: 16

Floating Sunfish
Floating Sunfish

Reputation: 5720

Multi-line Editing seems to be the only alternative solution so far.

Press and hold the Alt key and press either Up or Down so your cursor expands to multiple lines. Then just add // manually.

It isn't very intuitive, but it works. Hopefully, the VS Code team will address this issue someday.

UPDATE: This feature has now been added to the VS Code backlog! (https://github.com/microsoft/vscode/issues/88480)

Upvotes: 1

Related Questions