Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse toggle comment indented

Tags:

eclipse

I have following code:

public int doBam(int bam) {     if(foo) {         bam += 1;         if(bar) {             bam += 1;         }     }     return bam; } 

I want to comment out the if(bar) ...

When I do toggle comment in Eclipse 3.6 I will get this:

public int doBam(int bam) {     if(foo) {         bam += 1; //        if(bar) { //            bam += 1; //        }     }     return bam; } 

Can I make Eclipse to toggle comment like this instead?

public int doBam(int bam) {     if(foo) {         bam += 1;         //if(bar) {         //    bam += 1;         //}     }     return bam; } 
like image 524
Lesmana Avatar asked Nov 19 '10 14:11

Lesmana


People also ask

How do I toggle comments in Eclipse?

Ctrl - / to toggle "//" comments and Ctrl - Shift - / to toggle "/* */" comments.


1 Answers

Can I make Eclipse to toggle comment like this instead?

It's a three step process..

Step-1:- Select desired code.

if(bar) {   bam += 1; } 

Step-2:- Hit Control + 7 OR Control + /

//    if(bar) { //      bam += 1; //    } 

Step-3:- Hit Control + Shift + F

   // if(bar) {    // bam += 1;    // } 

UPDATE

Also, when uncommenting, the Eclipse autoformatter does not restore the previous indentation

Like commenting, uncommenting is also three step process:-

  1. select
  2. Contorl + /
  3. Control + Shift + F

it applies it's own formatting rules instead.

You can change these formatting rules. Windows --> Preferences --> Java --> Code Style --> Formatter --> Edit --> Comments Tab.

Eclipse does not allow editing default built-in profile. Create new profile and inherit all the properties from built-in profile, then you can customize the newly created profile.

like image 93
dira Avatar answered Sep 20 '22 11:09

dira