Add comments in Eclipse with a single keystroke

23 Sep

When you want to work with comments in Eclipse, you could use the slow way of moving to the start of the line, pressing // and then repeating this for all the lines you have.

Or you could use the quick way of adding a comment with a single keystroke no matter where the cursor’s positioned in the statement.

The same goes for Javadocs – there are just too many things to type before you can start commenting the good stuff. That’s why Eclipse also has a shortcut that let’s you add Javadoc to a field, method or class.


Keyboard shortcuts for comments and JavaDocs

Here are the keyboard shortcuts for manipulating comments.

Command Description
Ctrl+/ Toggle Comment Add/remove line comments (//…) from the current line. The position of the cursor can be anywhere on the line. Works with multiple selected lines as well.Alternatively, you can also use Ctrl+Shift+C, which probably works better on a QWERTZ keyboard (eg. German layout), or Ctrl+7.
Ctrl+Shift+/ Add Block Comment Wrap the selected lines in a block comment (/*… */).
Ctrl+Shift+\ Remove Block Comment Remove a block comment (/*… */) surrounding the selected lines.
Alt+Shift+J Add Javadoc Comment Add a Javadoc comment to the active field/method/class. See the notes below for more details on where to position the cursor.

Posted by on September 23, 2011 in Eclipse


4 responses to “Add comments in Eclipse with a single keystroke

  1. Agence de traduction français anglais

    October 3, 2011 at 5:08 PM

    I just added this website to my google reader, excellent stuff. Can’t get enough!

  2. Mae Lim

    October 11, 2011 at 7:34 PM

    very informative..thanks for sharin

  3. Rudie Hilton

    October 14, 2011 at 3:48 PM

    Thanks a lot for this. It is a big help. Keep posting!

  4. smugjoey

    November 6, 2011 at 1:13 PM

    Hey there! I know this is kinda off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having difficulty finding one? Thanks a lot


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: