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)?

4 Answers 4



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.

  • God help us please :)
    – Ansd
    Jul 19, 2011 at 21:20
  • God is working on it ↓
    – tim
    Mar 27, 2013 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*$';

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.


Today I found the "Tidy" option under Bundles > HTML and it worked great. (Ctrl-Shift-H). I can't speak to how well it works for other languages, though.

New contributor
laurenll is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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