NetBeans commenting

292 views Asked by At

I'm using the popular IDE NetBeans and I have problems commenting code on the same line. For example, let's say we have the following line:

<h1> Some text </h1> comment for h1

I would like to comment the part "comment for h1" through a key combination or some other means but without having to type manually and without transferring the comment string to the next line. I usually use ctrl+/ but this key combination comments the whole line, which is not what I want.

4

There are 4 answers

2
iklas On

select the texe and use Ctrl+Shift+C

2
Am_I_Helpful On

Why not Select & Replace all such occurences.

You can use Ctrl + Shift + H and enter the text which you want to replace.

Add the text (say comment for h1) to be commented in the field Containing Text, and replace that text with //comment for h1 in the Replace With field.

enter image description here

Then it will show you all the matches which you want to comment. You can select the desired places where you want to place comment before the text.

Finally, click on Replace ? Matches button. Voila, that's it...

enter image description here

0
Yavor On

I've decided to do this by recording 2 macros and assigning shortcuts to them:

  1. ctrl + shift + A for the html comment <!-- -->
  2. ctrl + shift + \ for the php comment /* */.

Both macros position the mouse cursor in the middle of the comment section so it is convenient to enter a comment. This doesn't work with an existing comment.

2
SaintLike On

You can always create your own keyboard shortcut, see how in this link.

Then you can customize your keyboard to replace your highlighted text with the same text with /* */ , // , <!-- --> or any others before/surrounding the text.

Example:

<h1> Some text </h1> comment for h1

Highlight the text you need to comment (comment for h1).

Use your customixed shortcut and:

<h1> Some text </h1> /*comment for h1*/

I haven't tested this, please tell me your feedback ;)