Eclipse comment/uncomment shortcut?

2020-01-27 09:28发布

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"
  ...
/ -->

16条回答
孤傲高冷的网名
2楼-- · 2020-01-27 09:44

Use

Ctrl + SHIFT + L which will open a list of all major shortcuts for eclipse.

  1. For single line java code comment : Ctrl + / (Forwards Slash) and

    Single line uncomment : Ctrl + \ (Backslash)

  2. For multiple line java code comment : Ctrl + Shift + / (Forwards Slash) and

    Multiline uncomment : Ctrl + Shift + \ (Backslash)

  3. For single line xhtml code comment/uncomment : Ctrl + Shift + c

  4. 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楼-- · 2020-01-27 09:44

For a Mac it is the following combination: Cmd + /

查看更多
孤傲高冷的网名
4楼-- · 2020-01-27 09:45

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

查看更多
在下西门庆
5楼-- · 2020-01-27 09:48

CTRL + 7

does comment/uncomment in the Java Editor.

查看更多
倾城 Initia
6楼-- · 2020-01-27 09:49

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.

查看更多
我想做一个坏孩纸
7楼-- · 2020-01-27 09:49

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.

查看更多
登录 后发表回答