2

How do I comment or uncomment code in Textmate 2?

I came across How do I use a shortcut to comment out code automatically in Textmate? , but it's for Textmate 1.x, and "Bundles" > "Source" > "Comments" doesn't have "Comment line".

I'm using TextMate 2.0-beta.7.1.

I recall disabling command + / because it was causing problems while working on Rails apps, but I assumed that would just disable the keyboard shortcut, not the ability to comment and uncomment lines.

Community
  • 1
  • 1
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

2 Answers2

1

In TextMate 2.0.19 you can comment, or uncomment, a line or selection with the shortcut Cmd (⌘) + /.

If this shortcut doesn't work for you, you can do it like this :

  1. Select Bundles in the menu bar
  2. Select Source
  3. Select Comments
  4. Select Comment line

Happy coding


TIPS

Define a new shortcut for comment or uncomment

If the native shortcut doesn't work for you, define a new one like this :

  1. Select Bundles in the menu bar
  2. Select Edit Bundles...
  3. Select Source
  4. Select Menu Actions
  5. Select Comments
  6. Select Comment Line / Selection
  7. Click on Key Equivalent
  8. Type your shortcut
  9. Close the Bundles editor
  10. A prompt will ask you to confirm your changes
  11. Test it!

Others useful shortcuts

  1. Insert Block Comment : Option (Alt, ⌥) + Cmd (⌘) + /
  2. Insert Comment Banner: Select the word or text you want to use as a banner and Ctrl (⌃) + Shift (⇧) + B
  3. Insert Comment Header ( This will insert the name of the script and some useful details): You have to define it because in my case it was empty... I defined it with Ctrl (⌃) + Shift (⇧) + N

Use Help in TextMate

  1. Select Help in the menu bar
  2. type "comment"

This will brings you directly to the option comment line. I suggest doing that first because in most cases, you will find the answer.


Yohan W. Dunon
  • 502
  • 10
  • 18
  • 1
    Both the shortcut and the menu command are launching a little box saying "Preparing Ruby: Please wait while ruby 1.8 is prepared for use..." and TextMate no longer responds until I use "TextMate > Quit TextMate" from the menu and restart it. It doesn't actually comment the code (JavaScript in my case). Please help! – ADTC Aug 02 '23 at 09:23
  • @ADTC can you give more details about your OS version, your TextMate version? – Yohan W. Dunon Aug 06 '23 at 14:03
  • macOS Ventura 13.4.1 (c) (22F770820d), TextMate version 2.0.23 – ADTC Aug 16 '23 at 15:46
0

Bundles -> Source -> Menu Actions -> Comments -> Comment Line

Is that what you're looking for?

Graham P Heath
  • 7,009
  • 3
  • 31
  • 45