score:284

Accepted answer

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.

score:-1

for single line comment just use // and for multiline comments use /* your code here */

score:-1

select the text you want to block-comment/block-uncomment.

to comment, ctrl + 6

to uncomment, ctrl + 8

score:0

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.

score:0

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

score:0

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

score:1

using eclipe oxygen command + shift + c on macosx sierra will add/remove comments out multiple lines of code

score:2

it depends upon the version of os - for me it works with command + 7

score:3

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.

score:3

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

score:3

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!

score:4

in addition, you can change eclipse shortcut in windows -> preferences -> general -> keys

change eclipse shortcut

score:6

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 .

score:7

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)

score:10

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.

score:29

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.

score:73

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


Related Query

More Query from same tag