Cannot remove block comment in Eclipse after formatting

后端 未结 5 1674
野趣味
野趣味 2020-12-15 16:22

Eclipse\'s automatic formatter changes block comments such that the Source > Remove Block Comment does not completely remove the block comment. Source > Add Block Comment ad

相关标签:
5条回答
  • 2020-12-15 17:07

    I've run into this problem before and my solution is just to use line comments (//) generated by Eclipse instead of block comments. Select code, and then hit Ctrl-/ or Ctrl-7 to toggle // for every line selected. After formatting, those lines will get indented and formatted like text, but if you remove the comments (Ctrl-/ or Ctrl-7) and reformat, everything works fine.

    0 讨论(0)
  • 2020-12-15 17:07

    I dont know if this helps solve your problem, but I found this very much helpful in my case. Consider this text -

    String abc="abc";
    String def="def";
    System.out.println(abc+def);
    System.exit(0);
    

    After applying a block comment using CTRL + SHIFT + F.

    /*  String abc="abc";
    String def="def";
    System.out.println(abc+def);
    */System.exit(0);
    

    Just add - after /* to exclude this block from formatting -

    /*-  String abc="abc";
    String def="def";
    System.out.println(abc+def);
    */System.exit(0);
    

    Now Check Again!!!

    0 讨论(0)
  • 2020-12-15 17:18

    This may be a little late in the game, but I fixed this by disabling block comment formatting.

    Windows -> Preferences -> Java -> Code Style -> Formatter -> Edit -> Comments
    

    Then uncheck Enable block comment formatting.

    0 讨论(0)
  • 2020-12-15 17:21

    Use Ctrl + \ (Back Slash) to remove /* --- --- --- */

    0 讨论(0)
  • 2020-12-15 17:23

    One other alternative solution is use of Block Selection Mode in eclipse, which is quite fast enough and still keeps your other comments formatted. You just have to press few keys to remove comments.

    In windows you can toggle Block Selection Mode by ALT + SHIFT + A. Checkout the screenshot for more.

    Steps to follow,

    • Press ALT + SHIFT + A to toggle Block Selection Mode
    • Select vertical section of comment
    • Press Delete or Backspace
    • Press ALT + SHIFT + A again to disable Block Selection Mode
    • Save the file and you have uncommented the code finally!

    0 讨论(0)
提交回复
热议问题