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
:
- to quickly comment/uncomment a line (like ctrl + d is for removing single line)
- 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"
...
/ -->
Use
Ctrl + SHIFT + L which will open a list of all major shortcuts for eclipse.
For single line java code comment : Ctrl + / (Forwards Slash) and
Single line uncomment : Ctrl + \ (Backslash)
For multiple line java code comment : Ctrl + Shift + / (Forwards Slash) and
Multiline uncomment : Ctrl + Shift + \ (Backslash)
For single line xhtml code comment/uncomment : Ctrl + Shift + c
For multiple line xhtml code comment : Ctrl + Shift + / (Forwards Slash)
For multiple uncomment : Ctrl + Shift + \ (Backward Slash)
For Mac user it will be: ⌘ instead of Ctrl
For a Mac it is the following combination: Cmd + /
You can toggle the comment on one line or selection by using the shortcut Ctrl + / This adds/removes the // infront of the code line
You can block comment /* */ using the Ctrl + Shift + / eclipse shortcut
You can find a complete list of useful eclipse shortcuts here http://javatutorial.net/eclipse-shortcuts
CTRL + 7
does comment/uncomment in the Java Editor.
Ctrl + Shift + C . Works great on .java, .xhtml, .properties and maybe on others but I only tested these ones. Can comment single or multiple lines.
Single comment ctrl + / and also multiple line comment you can select multiple line and then ctrl + /. Then, to remove comment you can use ctrl + c for both single line and multiple line comment.