Visual Studio Code Does Not Comment-out Empty Lines

六月ゝ 毕业季﹏ 提交于 2020-08-20 04:39: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.


回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/53754218/visual-studio-code-does-not-comment-out-empty-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!