Andrew Grimm
Andrew Grimm

Reputation: 81538

How to comment or uncomment code in Textmate 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.

Upvotes: 2

Views: 1678

Answers (2)

Yohan W. Dunon
Yohan W. Dunon

Reputation: 530

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.


Upvotes: 1

Graham P Heath
Graham P Heath

Reputation: 7399

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

Is that what you're looking for?

Upvotes: 0

Related Questions