Comment/un-comment blocks of code (using // comments)

Is there a way in IntelliJ to comment and un-comment blocks of code with the // characters?

For example, assume that I have the following code fragment:


I'd like to highlight the first 5 lines of this fragment and then run some sort of IntelliJ tool on it so that after the tool completes, the code looks like this:

Later, I'd like to highlight the same 5 lines, and then run the inverse function to remove the comments and turn it back into the original code fragment.

Yes, I know that I can use +/ ... /+ comments, but I'm looking for the specific functionality that I have described here, using +//+ comments.

Is this possible in IntelliJ?

By the way, I believe that either NetBeans or Eclipse offers this functionality, but I don't want to use either of these, because I love working in IntelliJ.

7 comments
Comment actions Permalink

Hi,

Control + /

Lloyd Zusman wrote:

Is there a way in IntelliJ to comment and un-comment blocks of code with the // characters?

For example, assume that I have the following code fragment:

       Calendar cal = Calendar.getInstance();
>       cal.set(1900, 00, 01, 00, 00, 00);
>       Date startDate = cal.getTime();
>       cal.set(2999, 11, 31, 23, 59, 59);
>       Date endDate = cal.getTime();
> 
>       ListIterator lineItr = lines.listIterator();
> ]]>


I'd like to highlight the first 5 lines of this fragment and then run some sort of IntelliJ tool on it so that after the tool completes, the code looks like this:

 //      Calendar cal = Calendar.getInstance();
> //      cal.set(1900, 00, 01, 00, 00, 00);
> //      Date startDate = cal.getTime();
> //      cal.set(2999, 11, 31, 23, 59, 59);
> //      Date endDate = cal.getTime();
> 
>       ListIterator lineItr = lines.listIterator();
> ]]>

Later, I'd like to highlight the same 5 lines, and then run the inverse function to remove the comments and turn it back into the original code fragment.

Yes, I know that I can use +/ ... /+ comments, but I'm looking for the specific functionality that I have described here, using +//+ comments.

Is this possible in IntelliJ?

By the way, I believe that either NetBeans or Eclipse offers this functionality, but I don't want to use either of these, because I love working in IntelliJ.



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

simple comments on&off (//):
Highlight the lines and press ctrl-/


multiline comments on&off (/* */)
Highlight the lines and press ctrl-shift-/


0
Comment actions Permalink

Aha! Thank you very much!

I was looking for this in the Tools menu, and I didn't think of checking for keystroke commands.

0
Comment actions Permalink

Lloyd Zusman wrote:

Aha! Thank you very much!

I was looking for this in the Tools menu, and I didn't think of checking for keystroke commands.


You can also find it in the "Code" menu.

Bas

0
Comment actions Permalink

Lloyd Zusman wrote:

Aha! Thank you very much!

I was looking for this in the Tools menu, and I didn't think of checking for keystroke commands.


You can also find it in the "Code" menu.

Bas

0
Comment actions Permalink

Lloyd Zusman wrote:

Aha! Thank you very much!

I was looking for this in the Tools menu, and I didn't think of checking for keystroke commands.


You can also find it in the "Code" menu.

Bas

0
Comment actions Permalink

Sorry about the duplicates, I had some news client problems.

Bas

0

Please sign in to leave a comment.