15

Yes, this could be duplicate of Eclipse comment/uncomment shortcut? But, answers given their are not working for my case.

I have formatted java code and When I select and use ctrl + shift + / it looks like

/*
 * if (isKilled) { Log.i("TAG", "Killed"); }
 */

But when I use ctrl + shift + / for above selected code, eclipse is not un-commenting my code.

I tried ctrl + shift + \, ctrl + shift + / and ctrl + \. Nothing worked. I always manually remove *s even if commented code is very big.

How to do this? I also want *s to be removed.

Community
  • 1
  • 1
Sundeep1501
  • 1,510
  • 1
  • 18
  • 28
  • possible duplicate of [Eclipse comment/uncomment shortcut?](http://stackoverflow.com/questions/5534748/eclipse-comment-uncomment-shortcut) – 1ac0 Feb 12 '14 at 10:02
  • 1
    Afaik there is a tendency to move away from `/**/` comments in favor of `//` ones. The `//` comments are easily toggled for multiple lines by `Ctrl + Shift + C`. I guess that this simplicity of IDE support is the reason why many developers prefer `//` over `/**/`. – noncom Feb 12 '14 at 10:16
  • Yes `//` could be easy. But is their a way for `/***/` ? – Sundeep1501 Feb 12 '14 at 10:38
  • 1
    As of date in 2017 there is no solution for this ! – Sankalp Apr 04 '17 at 11:00
  • This is so far the best solution I found https://stackoverflow.com/a/34553134/1053496. – nantitv Jun 20 '17 at 14:47

9 Answers9

11

Try using Ctr+Shift+C This should work

Pratik Roy
  • 724
  • 1
  • 5
  • 21
8

For me Remove Block Comment (Ctrl + Shift + \) works but only if there is code on the first line of the comment, so your example does not work but:

/* if (isKilled) { Log.i("TAG", "Killed"); }
 */

does work.

greg-449
  • 109,219
  • 232
  • 102
  • 145
5

In Eclipse, To add and remove single line comments,

CNTRL+SHIFT+C

Example:

// if(i==1){
// ...
// }

To add and remove multi line comments,

CNTRL+SHIFT+/ --> add CNTRL+SHIFT+\ --> remove

Example:

/* if(i==1){
   ...
}
*/
harsha
  • 51
  • 1
  • 2
2

One partial solution to this is to disable block comment formatting.

If you do that, Eclipse will not add * for intermediate lines in multiline block comments when you format the code. And so you will be able to remove such block comments with Ctrl+Shift+\ or just by removing /* and */

In Eclipse for PHP (Windows), in the main menu Window->Preferences->PHP->CodeStyle->Formatter->Edit->Comments
Uncheck "Enable block comment formatting"

In other versions of Eclipse this option also exists but under a different path.

CITBL
  • 1,587
  • 3
  • 21
  • 36
1

It is basically a case when save actions is enabled in eclipse. When you put block comments using "Crtl + Shift + /" or by typing yourself as:

/*
 line 1
 line 2
 line 3
*/

and save it, the editor formats it to

 /*
 * line 1
 * line 2
 * line 3
 */

* are added on each intermediate lines. This results "Crtl + Shift + \" to fail to remove those "*" before the lines.

The solution is:

1- Use "Crtl + Shift + C" to comment and uncomment (toggle). Preferable one.

2- If you don't want to use "Crtl + Shift + C". This is a hack actually. When you save, the editor formats the code like:

 /*
  * line 1
  * line 2
  * line 3
  */

You intermediately undo (Crtl + Z) it. The editor will put it back to earlier stage but code is saved like:

/*
 line 1
 line 2
 line 3
*/

Now you can use "Crtl + Shift + \" to uncomment when needed. The * won't trouble you :)

Dexter
  • 4,036
  • 3
  • 47
  • 55
1

I am having this problem since ever. Always had in mind that Ctrl + Shift + C would away be the right way to comment but it never "uncomment".

Instead just change for to use Ctrl + / (for groups also) , or Ctrl + Shift + / for /**/ if you prefer.

It never fails, do not stress yourself again.

maihe
  • 43
  • 8
0

This might not be as easy. But still it works! I use Ctrl+F to get the Find and Replace window, check the Regular expressions check box and use this regex ^(\s*)/?\*/?(.*)$ and \1\2 in the replace part and click "Replace All". If you want to uncomment only one commented code part, you can select that area and use the radio button "Selected lines" in the scope part.

Regex break up ^ #denotes start of the line. To avoid matching * in other part of the code. ( #first group. To preserve the indentation \s* #selects the tab/space. The indentation ) #first group is closed /? matches the forward slash in the first line of comment \* matches the star(Asterik) in the comments. backward slash is used as a delimiter /? matches the forward slash in the last line of comment ( #second group. To preserve the indentation .* # the actual code to be uncommented ) #second group is closed $ # till the end of the line

Hope this helps!

RamValli
  • 4,389
  • 2
  • 33
  • 45
0
  1. Select the lines of code u wanna comment/uncomment.

  2. Then hit "Ctrl + / " to comment/uncomment.

-1

Just replace * with whitespace and remove extra slashes.