可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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"
...
/ -->
回答1:
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.
回答2:
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
回答3:
CTRL + 7
does comment/uncomment in the Java Editor.
回答4:
- Single line comment Ctrl + /
- Single line uncomment Ctrl + /
- Multiline comment Ctrl + Shift + /
- Multiline uncomment Ctrl + Shift + \ (note the backslash)
回答5:
An easier way is to press Ctrl + Shift + C, just like in Code::Blocks
回答6:
Select the code you want to comment, then use Ctr + / to comment and Ctrl + \ to uncomment. It may not work for all types of source files, but it works great for Java code.
回答7:
In eclipse Pressing Ctrl + Shift + L, will list all the shortcuts.
回答8:
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.
回答9:
A simple way of doing is to press Ctrl + Shift + C, on the lines of your code.
For comment and for uncomment do same .. :)
回答10:
Comments In Java class
- Toggle/Single line Comment ( Ctrl+/ ) - Add/remove line comments (//…) from the current line.
- Add Block Comment ( Ctrl+Shift+/ ) - Wrap the selected lines in a block comment (/*… */).
- Remove Block Comment ( Ctrl+Shift+/ ) - Remove a block comment (/*… */) surrounding the selected lines.
- Add Javadoc Comment ( Alt+Shift+J ) - Add a Javadoc comment to the active field/method/class. See the notes below for more details on where to position the cursor.
Comments In HTML/XML/Config file
- Add Block Comment ( Ctrl+Shift+/ ) - Wrap the selected lines in a block comment (< !-- -->).
- Remove Block Comment (Ctrl+Shift+\) - Remove a block comment (< !-- -->) surrounding the selected lines.
回答11:
Ctrl + 7 to comment a selected text.
回答12:
For a Mac it is the following combination: Cmd + /
回答13:
For those who like to customize things (and screw them up), some tips:
In "Preferences" - "General" - "Keys", type "comment" to get a full list of comment key combination in all editors. Be sure only to edit, not copy commands(because you cannot erase created ones).
For HTML files, look for those with scope "Editing HTML files". The names are confusing, yes, but the description shows more or less when each and every key is used.
At last, I am only able to define block comment in HTML here. It works for both HTML code and Javascript code(add at the beginning and the end, <!--
and -->
if is HTML, and add /*
and */
if is Javascript). (I remember once there may be a "line comment" key (add comments for every line) but now it is not there anymore. If someone knows how to find it and tell me, I will be very grateful.)
The category must be Edit
. Source
does not work.
EDIT:
I found how to configure XML Toggle comment! The category should be Edit
, too. Then you can toggle comment in **XML Editor(the one with "Design" and "Source" tabs).
回答14:
Ctrl+/ to toggle "//" comments and Ctrl+Shift/ to toggle "/* */" comments. At least for Java, anyway - other tooling may have different shortcuts.
Ctrl+\ will remove a block of either comment, but won't add comments.
EDIT: It's Ctrl on a PC, but on a Mac the shortcuts may all be Cmd instead. I don't have a Mac myself, so can't easily check
回答15:
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.
回答16:
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