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.

- 573
- 6
- 19

- 1,421,763
- 867
- 9,128
- 9,194
-
10For the record: on Mac, `Command-/` makes it a `//`, and `Ctrl-Command-/` makes it a `/* */`. Removing comments is done with `Ctrl-Command-\\ ` . – Angelo van der Sijpt Jul 26 '12 at 10:39
-
3I tried it on a Mac. To remove `//` comments, I just did `Command-/` again. – Noah Lavine Nov 12 '12 at 17:27
-
1@Griffin Me neither, but Ctrl+Shift+\ works for /* */ style comments. // style comments can be removed with Ctrl+/ – Inversus May 20 '13 at 20:06
-
@IOS_Dev: I suspect that's a general Mac/PC thing. Will edit to note. – Jon Skeet Jul 16 '13 at 18:17
-
Also found that other aware editors put the "appropriate" comment tag in for their syntax. Doing work in Puppet manifests gets me a "#". – 8None1 Jan 09 '14 at 17:58
-
Ctrl-Shift-/ for me only collapse all methods and not related to comment – ashraf mohammed Oct 29 '14 at 14:03
-
1@ashrafmohammed: Under "Preferences", go to the keyboard shortcut (type Keys into the filter) and then look for comments. Maybe you've got different key bindings to the default. – Jon Skeet Oct 29 '14 at 14:07
-
IDK why, but the command `ctrl + shift + \` to remove block comment doesn't work for me eclipse mars for some reason. – Lucky Aug 12 '16 at 12:25
-
Is there a way to make the `//` appear next to the code instead of the beggining of the line? – Katu Jul 29 '21 at 08:15
-
@Katu: I don't know offhand, but I'd look at your code formatting options. – Jon Skeet Jul 29 '21 at 08:47
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

- 573
- 6
- 19

- 99,403
- 23
- 97
- 120
-
a have code folding enabled so ctrl + / enables-disables that. For me control + shift + 7 give me // comment-uncomment . – roho Oct 17 '12 at 13:43
-
I would advise people against using the block comment shortcuts as the implementation isn't, shall we say "smart". If you have block comments within the section you plan to block comment out, the start/end tags will be removed! So when you try to undo the commenting you now have to insert the missing "/* */" tags. At least this is what i see using Juno under Linux. Test it out first! – mohbandy Oct 23 '13 at 15:24
-
The command to prepend every line also works in python; it just adds or removes `#`. – Aaron Swan May 19 '21 at 12:41
For Eclipse Editor
For Single Line (Toggle Effect)
Comment : Ctrl+Shift+c
Uncomment: Ctrl+Shift+c
For Multiple Lines (Toggle Effect) (Select the lines you want to comment)
comment : Ctrl+Shift+c
Uncomment: Ctrl+Shift+c
It is for all html , css , jsp , java . It gives toggle effect.

- 845
- 11
- 22
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.

- 3,956
- 8
- 38
- 58

- 603
- 9
- 23
-
Same happened to me, seems it should be some interaction with a plugin. – Yaroslav Oct 01 '12 at 09:33
-
1+1 Using Ctrl + 7 (on the number keys above the alphabet keys) toggles the currently selected block with `//`, even in Java code. Kind of annoying that it'll double comment lines, which potentially makes it impossible to quickly uncomment them all if one of the lines has more comments than the others... oh well, good enough! – ArtOfWarfare Nov 01 '12 at 18:36
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)

- 175
- 2
- 9
For single line comment you can use Ctrl+/ and for multiple line comment you can use Ctrl + Shift + / after selecting the lines you want to comment in java editor.
On Mac/OS X you can use ⌘ + / to comment out single lines or selected blocks.

- 3,956
- 8
- 38
- 58

- 465
- 6
- 9
for java code
if you want comments single line then put double forward slash before code of single line manually or by pressing Ctrl +/
example: //System.Out.println("HELLO");
and for multi-line comments, Select code how much you want to comments and then press
Shift+CTRL+/
Now for XML code comments use Select code first and then press Shift+CTRL+/ for both single line and multi-line comments

- 3,956
- 8
- 38
- 58

- 3,035
- 23
- 25
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!
-
1Greetings and welcome to StackOverflow. Generally answers for questions which already have highly voted answers are expected to add somehow to what's already provided. Is there a way you can update your answer to illuminate how it adds something new to what's already been said? – Louis Langholtz Jan 13 '19 at 20:15
It depends upon the version of OS - for me it works with Command + 7

- 29
- 3
-
Similar here, using Windows 10 and a Spanish keyboard I need to type Ctrl + 7 to comment/uncomment code. Shift+7 produces /, there is no direct key to type / unless you have numeric keyboard. – Antonio Rodríguez Jun 07 '19 at 11:48
Using Eclipe Oxygen command + Shift + c on macOSx Sierra will add/remove comments out multiple lines of code

- 1,621
- 1
- 12
- 12
Using Eclipse Mars.1 CTRL + / on Linux in Java will comment out multiple lines of code. When trying to un-comment those multiple lines, Eclipse was commenting the comments. I found that if there is a blank line in the comments it will do this. If you have 10 lines of code, a blank line, and 10 more lines of code, CTRL + / will comment it all. You'll have to remove the line or un-comment them in blocks of 10.

- 7,373
- 6
- 36
- 49

- 1
- 1
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

- 2,956
- 1
- 27
- 46
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

- 1,487
- 1
- 12
- 20
For single line comment just use // and for multiline comments use /* your code here */

- 3,035
- 23
- 25
-
1Please note that the question is if Eclipse has a hotkey, not what the syntax itself is. – S.L. Barth is on codidact.com Sep 15 '16 at 12:25
Select the text you want to Block-comment/Block-uncomment.
To comment, Ctrl + 6
To uncomment, Ctrl + 8

- 1,430
- 1
- 12
- 22

- 33
- 1
- 6