Home > Back-end >  How do i reformat java comments, to remove whitespaces in intellij?
How do i reformat java comments, to remove whitespaces in intellij?

Time:11-22

What IntelliJ format setting should be set to automatically change line comments to look like:

    validcode();
    // comment1
    // comment2
    validCode();

from lookin like this:

    validcode();
    //       comment1
    //       comment2
    validCode();

No result with all the settings i have tried.

CodePudding user response:

There may be a way to do this via editor settings. But you could remedy this using a regex replace all:

Find:    //\s{2,}(.*)$
Replace: // $1

This would be under the assumption that once a // style comment has been declared, the remainder of that line belongs to the comment.

Note that you could even apply the above replacement to all files in the project, or all Java source files in the project, module, etc.

  • Related