47

In IDEA, we can comment/uncomment lines in java as well as html,jsp, xml files with the same keyboard shortcut combination. I tried doing that in eclipse but was not able to comment out lines in html,jsp and xml files. Is there a way to do it in Eclipse? Also I would like to know whether bulk comment is also available for non-java files.

Thunderhashy
  • 5,291
  • 13
  • 43
  • 47

5 Answers5

89

I use Shift+Ctrl+/ to Add Block Comment in both XML and JSP files (works at the line level or for a selected block).

Just in case, if you are looking for a particular shortcut, you can use Shift+Ctrl+L to Show Key Assist (i.e. the Commands and their Bindings).

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 2
    +1. "Show Key Assist" is good advice ;) http://stackoverflow.com/questions/1986195/eclipse-list-of-default-keyboard-shortcuts/1986236#1986236 – VonC Feb 06 '10 at 10:14
  • +1. And if you don't like to key binding showed in Show Key Assist, open Preferences/General/Key, and set your own... – Zoltán Ujhelyi Feb 06 '10 at 12:45
  • @zoltán-ujhelyi Actually, in my Eclipse installation the default binding didn't work in JSP editor (even thoughs its scope was 'In Dialogs and Windows'), so I had to copy it and set When = JSP Source. – GreenhouseVeg Mar 03 '17 at 14:55
  • short key for this comment - "<%-- commented --%>" ? – Derrick May 24 '18 at 10:39
47

I believe CTRL+SHIFT+C works in XML, not sure about JSP. I think it lacks consistency in the various editors, and some don't have this shortcut.

harschware
  • 13,006
  • 17
  • 55
  • 87
24

I found Ctrl + Shift + C works in JSP too, it works like:

<tiles:insertDefinition name="" >
</tiles:insertDefinition>

<!--<tiles:insertDefinition name="" >-->
<!--</tiles:insertDefinition>-->

add comment tag line by line, and select the sentences, use Ctrl + Shift + C again can toggle remove the comments.

Ctrl + Shift + / add block comment in JSP, works like:

<tiles:insertDefinition name="" >
</tiles:insertDefinition>

<!--<tiles:insertDefinition name="" >
    </tiles:insertDefinition>                       
-->

can use Ctrl + Shift + \ to remove the block comment.

PS: I want to find out, which eclipse shortcut can add/remove <%-- --%> comment in JSP?

yuting_lv
  • 341
  • 2
  • 3
7

In eclipse they use same kind of shortcut to do this which is for:

I found Ctrl + Shift + C works in XML and JSP.

Single line

comment Ctrl + /

uncomment Ctrl + /

Multiline

comment Ctrl + Shift + /

uncomment Ctrl + Shift + \ (note the backslash)

Hope this helps!

tk_
  • 16,415
  • 8
  • 80
  • 90
2

In Mac, for xml:

Command+/ - To comment a line or selected block of lines

Command+\ - To uncomment a line or selected block of lines

This works in Eclipse Photon (4.8.0)

Omkar Shetkar
  • 3,488
  • 5
  • 35
  • 50