18

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.

3
  • 1
    A duplicate of stackoverflow.com/questions/52919515/commenting-blank-lines but there is apparently no answer - probably not possible with line comments vs. block comments. Commented Dec 13, 2018 at 5:32
  • 1
    @Mark Weird that that question didn't come up when I tried to search for this issue. Thanks for the heads up. :) Commented Dec 13, 2018 at 6:16
  • 3
    This is especially annoying for diffs. Instead of handling a block comment as a single change, every diff method I've worked with by default show each group between blank lines as a separate change Commented Mar 4, 2020 at 20:57

3 Answers 3

19

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, yes. I remember filing that issue. I'm so glad they actually decided to implement it!
6

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.

Comments

1

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)

2 Comments

You could have a look at stackoverflow.com/questions/59418108/… in the meantime. It comments empty lines.
@Mark Thanks! I personally don't want to use it because it's a little too messy for me, but I hope it helps someone out there!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.