Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I like Textmate but its really driving me crazy when it comes to formatting code whatever the language I'm working with. Is there any way to format code? shortcut, bundle or anything that can help (eg ctrl+shift+F in netbeans)?

share|improve this question

migrated from Jul 20 '11 at 11:30

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted


There is a Reformat Paragraph command under the Text menu but it is mostly useless for programming.

Some language-specific bundles (like Javascript Tools) offer reformatting options, though.

share|improve this answer
God help us please :) – Ansd Jul 19 '11 at 21:20
God is working on it ↓ – tim Mar 27 '13 at 19:17

Textmate 2 has indenting intelligence for each language (as much as it can: See below).

You can re-indent a block with ⌥⌘-[ You can re-wrap lines with ^-Q You can align code on symbols with ^⌥⌘-9

Example indentation rule in Settings (no need for casual users to edit these)

{   increaseIndentPattern = '(?x)
    (   \{ (?! .* \} ) .*
    |   array\(
    |   (\[)
    |   ((else)?if|else|for(each)?|while|switch) .* :
    )   \s* (/[/*] .*)? $';
decreaseIndentPattern = '(?x)
    ^ (.* \*/)? \s*
        (\})         |
        (\)[;,])     |
        (\][;,])     |
        (else:)      |
indentNextLinePattern = '(?x)^(?! .*? (<\?|\?>) )
    ( . ( (?![/*]) | /(/.*$|\*.*?\*/ \s*) ) )*
    [^\s;:{}(,] \s*
    ( /(/.*$|\*.*?\*/ \s*) )*
unIndentedLinePattern = '^\s*$';
share|improve this answer

If all you want to do is re-indent:

  1. select code
  2. text > indent line

All it does is indent each nested level more than its parent. It wont erase empty lines or create any carriage returns.

Personally I love this because it seems to be language agnostic. Tested with HTML, ERB, CSS, SCSS.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.