Blankman
Blankman

Reputation: 266910

How to toggle commenting and uncommeting code in IDEA?

Is there a way to comment/uncomment a block of selected text in IDEA?

Upvotes: 11

Views: 14081

Answers (7)

cpurdy
cpurdy

Reputation: 1236

This functionality also seems to not work in the latest version(s) for file types that you add to IDEA. For example, it works fine for .java files, but not for other file types that I've configured.

Edit: Here's a thread on the Jetbrains site explaining this. Apparently it needs a custom plug-in for each file extension: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000118344-Comment-with-Line-Comment-does-not-work

Upvotes: 0

Boommeister
Boommeister

Reputation: 2107

If the Cmd+Shift+/ doesn't work for you (often the case with spanish / german and other keyboards) and you don't want to set it to US/EN keyboard, then use:

Cmd+Alt+s to open the IntelliJ-settings -> select Keymap and search for "Comment with Line Comment" or "Comment with Block Comment". Then rightclick on it and select "add Keyboard Shortcut" and set your own shortcut, for example: Cmd+Shift+NumPad /

Upvotes: 1

K Rakesh patra
K Rakesh patra

Reputation: 3

use this Simbol /* write any thing */

For windows Ctrl + Shift + / For mac Cmd+Shift+-

Upvotes: 0

Jason Braucht
Jason Braucht

Reputation: 2368

Jetbrains provides a printable reference card with the default set of Windows and Mac key bindings.

For the benefit of others who might stumble across this question & answers... In addition to the windows key binding provided in other answers, there is also a keystroke for toggling a comment bock in IntelliJ IDEA on the Mac.

Line Comment

+/

Block Comment

+SHIFT+/

Upvotes: 1

iusting
iusting

Reputation: 8373

The Cmd+Shift+/ doesn't work under Mac with Spanish keyboard layout, because this shortcut it's bind to the main character on the key, which in this case is 7, not /.

For someone else having the same issue, pressing the Cmd+- (Ctrl+- in Windows) is the shorcut for single-line comment while Cmd+Shift+- works for multi-line comments.

Upvotes: 0

gnat
gnat

Reputation: 6226

with Shift this makes for block style comments /**/, without it for line style comments Ctrl + / -> \\ (tested with IDEA 10U)

Upvotes: 4

duffymo
duffymo

Reputation: 308733

Yes, highlight the block and type Ctrl + Shift + /. To uncomment, just repeat.

Upvotes: 21

Related Questions