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.
Change the Keyboard layout to US-Keyboard if US keyboard is not selected. If it is US keyboard then, The shortcut key might have changed. You can edit your preferences on VS code.
Windows: Ctrl + K + U. Mac: Command + K + U.
Fortunately, if you use Visual Studio Code, commenting out a block of code is really quick and easy. All you need to do is select that code block with your mouse, then press the following key combination: Ctrl + K then press Ctrl + C if you're using Windows.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With