How to comment a block in Eclipse?

前端 未结 17 2104
一整个雨季
一整个雨季 2020-12-07 08:52

Does Eclipse have a hot key to comment a block? and to uncomment a block?

相关标签:
17条回答
  • 2020-12-07 09:02

    In addition, you can change Eclipse shortcut in Windows -> Preferences -> General -> Keys

    change Eclipse shortcut

    0 讨论(0)
  • 2020-12-07 09:05

    I came here looking for an answer and ended up finding it myself, thanks to the previous responses.

    In my particular case, while editing PHP code on Eclipse Juno, I have found that the previous commands won't work for me. Instead of them, I should press Ctrl+ 7 (on the superior number key) to obtain the double bar comment ("//"). There's no way I can comment them with the previous mentioned key combinations.

    0 讨论(0)
  • 2020-12-07 09:06

    It depends upon the version of OS - for me it works with Command + 7

    0 讨论(0)
  • 2020-12-07 09:07

    I have Eclipse IDE for Java Developers Version: Juno Service Release 2 and it is -

    Every line prepended with //

    ctrl + / for both comment and uncomment .

    0 讨论(0)
  • 2020-12-07 09:07

    As other answers pointed out, the following shortcuts are defined by default (I'm referring to editing java source - shortcut bindings can be found in eclipse Window>Preferences, under 'General'/'Keys', search for 'comment'):

    • to add a block comment, the shortcut (binding) is: Ctrl + Shift + /
    • to remove a block comment, the shortcut (binding) is: Ctrl + Shift + \

    Unfortunately, these shortcuts did not work for me (on Eclipse Java EE IDE for Web Developers, version: Juno Service Release 2).

    The reason, I think, is my keyboard layout (QWERTZ keyboard layout used in Germany - see here for further information), where '/' actually has to be written via 'Shift + 7'.

    I therefore had to change the shortcut bindings for comments (just did it for editing java source) in the eclipse preferences (under 'General'/'Keys') as follows:

    • Change the binding of command 'Add Block Comment' (when 'Editing Java Source') from 'Ctrl + Shift + /' to 'Ctrl + Shift + 7'
    • Change the binding of command 'Remove Block Comment' (when 'Editing Java Source') from 'Ctrl + Shift + \' to 'Ctrl + Shift + 8'
    • Unbind the binding 'Ctrl + /' for command 'Toggle Comment' (when 'Editing Java Source'); instead of assigning a new binding, I simply unbound this shortcut, as there already was one with Ctrl+7 and one with Ctrl+Shift+C (which both work for me)
    0 讨论(0)
  • 2020-12-07 09:07

    I have Mac ,I was also facing problem to comment multiple line in STS

    I have tried

    single line comment:

    command+/
    

    Multi line comment:

    control+command+/ 
    

    Multi line uncomment:

    control+command+\ 
    

    And it was success

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