Java – Eclipse comment/uncomment shortcut

eclipsejavakeyboard shortcutsshortcut

I thought this would be easy to achieve, but so far I haven't found solutions for comment/uncomment shortcut on both Java class editor and jsf faceted webapp XHTML file editor :

  1. to quickly comment/uncomment a line (like ctrl + d is for removing single line)
  2. being able to choose multiple lines and comment/uncomment it

For example :

single line java code, from :

private String name;

into

//private String name;

multiple line java code, from :

private String name;
private int age;

into

/*private String name;
private int age;*/

single line xhtml code, from :

<h:inputText ... />

into

<!-- h:inputText ... / -->

multiple line xhtml code, from :

<h:inputTextarea
  rows="xx"
  cols="yy"
  ...
/>

into

<!-- h:inputTextarea
  rows="xx"
  cols="yy"
  ...
/ -->

Best Answer

For single line comment you can use Ctrl + / and for multiple line comment you can use Ctrl + Shift + / after selecting the lines you want to comment in java editor.

On Mac/OS X you can use + / to comment out single lines or selected blocks.