How to comment a block in Eclipse?

Viewed 351521

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

17 Answers

Ctrl-/ to toggle "//" comments and Ctrl-Shift-/ to toggle "/* */" comments. At least for Java, anyway - other tooling may have different shortcuts.

Ctrl-\ will remove a block of either comment, but won't add comments.

Note: As for Eclipse CDT 4.4.2, Ctrl-Shift-/ will not uncomment a "/* */" block comment. Use Ctrl-Shift-\ in that case.

EDIT: It's Ctrl on a PC, but on a Mac the shortcuts may all be Cmd instead. I don't have a Mac myself, so can't easily check.

There are two possibilities:

Every line prepended with //

ctrl + / to comment
ctrl + \ to uncomment

Note: on recent eclipse cdt, ctrl + / is used to toggle comments (and ctrl + \ has no more effect)

Complete block surrounded with block comments /*

ctrl + shift + / to comment
ctrl + shift + \ to remove

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 .

For JAVA :

Single line comment:

               // this is a single line comment

To comment: Ctrl + Shift + C

To uncomment: Press again Ctrl + Shift + C

Multiple line comment:

         /* .........
            .........
            ......... */ 

First, select all the lines that you want to comment/uncomment then,

To comment: Ctrl + Shift + C

To uncomment: Press again Ctrl + Shift + C

I hope, this will work for you!

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

Eclipse Oxygen with CDT, PyDev:

Block comments under Source menu

Add Comment Block Ctrl + 4

Add Single Comment Block Ctrl+Shift+4

Remove Comment Block Ctrl + 5

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

Select the text you want to Block-comment/Block-uncomment.

To comment, Ctrl + 6

To uncomment, Ctrl + 8

Related