Joao Carlos 4 years ago • updated by Alan Colyer 3 weeks ago 56
Hello, I started using ST2 today, and I found out it does not have a feature I love in other text editors (not many have this however), that is auto fix identation or autoformat, depending on what the editor chooses to call it.

What does it do? Well, say you get a file where the identation is all wrong, for example a post-processed CSS file where all line breaks have been omitted, along with extra spaces,etc, so all identation is wrong.

This function would auto indent the file for us into a humanly readable structure. Eclipse has this, so does Visual Studio and Notepad++ (if i am not mistaken by using a plugin)

Yes! Exactly! Emacs does exactly this (C-x h TAB) and it's why I generally use Emacs nowadays... I wish I could use ST for my coding though... 


Yes, this great feature exists in Netbeans (shift + alt + F), and in Aptana  (shift + ctrl + F). I would love to see that in sublime!

As a brand new user of ST2, I was just searching for this ability, too.  I'm using ST2 in vintage mode (such an awesome editor to start with, then I find out about Vintage mode: yowza!).

In vim, I am used to selecting a block of code, and then just hitting "=" to have it reformat all the lines with proper indentation levels based on current settings.

This would be great.  I use this all the time in other editors, and I miss it dearly in ST.
Lets try and push this so it gets implemented :D
It physically hurts me that this feature is not implemented.
I need this. My JSON data doesn't look up to par.
+1.  This feature saves a lot of time and makes the code much more clean.  It can be a lot of work to get right though, since people will want to over-ride the default formatting.  Anyone volunteer to creating the plugin?
Same here would really like this feature.
Y u no fix autofix identation?!
Good news, folks, this feature was implemented in build 2133 (10/18/2011)!
What's the keyboard short-cut / menu-item to initiate the command?
"Edit/Line/Reindent" or "Reindent Lines" in the Command Palette
If you are using Vintage mode, re-indent is mapped to "=".  I don't think there is a default mapping for it in regular mode, though you could create your own in the Key Bindings preferences.
While the function/command is in place it is lacking ALOT.  It doesn't work well when working in php and HTML on the same page.  I think it is just lacking HTML indent guidelines, it recognizes php functions and arrays etc, but when it comes to indenting HTML code it just indents one level deep and quits.

I agree. There is a difference between re-_indent_, and auto-_format_ -- which is to automatically go through and insert the newlines and indentation for me. "prettyify" or "autoformat" should be able to take an xml file which is all one line, and then divide it into indented lines.

Hey Jon,

OK, first, Sublime Text 2 is great, and I don't want to seem like a complainer.  I'm very happy with it.  There's always something to complain about :)

But I do want to say that a format command is something I've used a lot in previous editors.  It's something I find really useful.  And line re-indent just doesn't cut it - I'm not even sure this is the same command as format, but if it is it doesn't work very well.  I guess what I'm looking for is a "beautify" feature.  Eclipse calls it "format".

I see there are plugins for beautification of code, but it would be nice to have that built-in, rather than having to download a different one for each language.

In the meantime I'll see about installing beautification plugins, which might work just fine.  

It's nice how easy it is to install plugins for Sublime, by the way, so thanks for that.

This feature is essential for team coding environments where there is a uniform standard for code formatting.

It might be a revenue generator for use by commercial shops...

Sublime Text 2 is the -only- code editor for Mac that does what I need. Proper code formatting is the last missing element. Thank you!

Using "format" and "beautify" plugins piecemeal is a poor substitute.  They each have different key bindings, they vary in quality, they tend to not be configurable, and they aren't available for many/most languages.  Plus it takes work to install them all.

It would be great if there was just one key binding for the "beautify" command, and it determined which formatting style to use based on the file type.  It would be great if there were a uniform way to specify formatting style.  This is something Eclipse gets right.

Just arrived here seeking the same functionality use this in other editors/ide's and is a heavily used feature which I would love to see in ST2 for sure!
I am looking for the same feature, a quick keyboard shortcut that indents the selected text based on the formatting of the current file type (using the tab/space configuration) and then clean trailing spaces on each line. I use this all the time in other editors before saving and closing the file and would really like to see an equivalent feature in Sublime.
I think that the Line->Reindent feature does not work vey well also with Javascript.
It would be great to have it fixed
Would be pretty awesome if there was an autoformat like in Netbeans.
Ok, so what's the status of this? I know about Edit>>Line>>Reindent, but it does a pretty lousy job with html.  Any plugins which do it better?  #frustrated
I can understand it having troubles with some of the more complicated languages, especially languages interspersed in HTML (i.e. PHP + HTML in one document), but that it can't do relatively simple pure-HTML is frustrating.

It's one of the major things preventing me from switching from TextMate. They've always been very vigilant with correct and quick auto-indent.
There are plugins available for ST2 that work fairly well, even they have some trouble with it, but for the most part they work.  Like Tags,  check out wbond.net he has a list of tons of ST2 plugins.
I have spent two whole hours having fun, discovering interesting plugins, of course the drawback is about keyboard shortcuts, some plugins might override previous plugins shortcuts, so we must pay attention to these details. And finally, now, I got my head into the wall... I find really exhausting and irritating trying to make Sublime Text 2 format PHP code. I used JSFormat but it puts extra spaces when you call class attributes such as "Person - > FullName". It is also annoying how curly braces is handled using this JS plugin... Anyway, I think we have to type and indent manually, and also send our thoughts NOW to Sublime website: an autoformatter for EcmaScript languages is a must have. The reindent is not useful when I have //comments in my code. :-/
This really needs work. ERB Support would be awesome!
While it works with 'reindent' I like my array closing bracket under my opening array:

And not like:


Is there a way to change this?

Found a way to change the tap size at view->Indentation->Tab Width

Anybody know of a plugin like SmartTabs from Emacs? This is one feature I am dying to have!
No but I would like that too
Sublime-HTMLPrettify plugin worked for me with HTML. You can install using Package Control. It is listed here: http://wbond.net/sublime_packages/community
Good God!  I paid my money and found out this tool is missing this critical functionality like Emacs.

Time to add this NOW!


It's there http://www.sublimetext.com/blog/articles/sublime-text-2-build-2139

I bound it to super-shift-r like eclipse in my user keys. 

I came up with this unholy plugin because I couldn't live with the current state of reindent for HTML in particular.


It shells out to Emacs.

I know.


We need this!


C'mon, when this is comming?


....this absolutely needs to be done.


Yes, this is driving me nuts. Reindent is not smart enough. Comments in PHP are not understood. And interspersing HTML and PHP really confuses it.


This is the single reason I'm using Aptana over Sublime right now...the Source Formatting just does it for me.


me too i am struck to aptana

My first gripe with this feature (on my first day of using Sublime) is that it get's confused by Javascript comments (//) in html files.  Ugh.


'Reindent Lines' has been available (and broken for many, if not most, languages) for a while now, especially when encountering comments. I am frustrated by the fact that Jon is opting to work on new features before fixing basic (and currently broken) functionality, including some of the most glaring and well reported bugs in ST2, as witnessed by the number of messages both here and on the Sublime forum. While it is clear that he needs to make money and no new features for ST2 are expected, fixing a broken product is; I have been using IntelliJ IDEA after getting it during the 75% discount and while it is not as lightweight and to my liking as Sublime would be if it were working right, it is a product that works as advertised. I'll give ST3 a pass until Jon decides to honour the thousands of people that have supported him, by focusing on a few well-functioning features, not a number of quasi-broken ones.

I switched to Sublime after being a BBEdit user for years. I want to love it, but I cannot comprehend why it doesn't offer the basic feature of auto-indent/format. I use either BBEdit or Aptana when I have to reformat code. #scratching head.


There are actually many plugins for ST to reformat code which work well, despite the native auto-indent issues. So no reasons to change editor in order to reformat.

Sometimes a small thing makes a big difference. If you think it's not important, OK, then such unimportant thing is the "last straw" that blocks me to buy. I think this is really a good opportunity for sublime text to be really outstanding, because if you look at the text editor software, I really didn't see anyone which is doing good at code auto format, with the only exceptions of the Eclipse family and Netbeans.


This is the number one thing that keeps me from buying a license for ST2, and has me continuing to wait to see if TextMate 2 fixes its large-project performance issues. 

I kept a development log for one month at a granularity of 15-30 minutes where I recorded for every block of time what most negatively affected my productivity / sense-of-flow and having to manually fix code indents was the winner by a significant margin.

With this actual data to back up my gut feeling, there is zero chance I'll buy ST before it has working AUTO smart indent. It has to be AUTO, i.e., happen automatically whenever I hit return or paste a chunk of code.


Hi every one, my name is Cara and i want to tell you all of how i got my man back with the help of Dr. Agba. My husband of seven years left me and our son for another woman saying that he is tired of me and want to move on with his life without me, i knew that something was wrong cause i did nothing wrong to him that can  lead to break up. this break up left me in a confused state and there was nothing i could do until i told a friend about it who told me about this spell caster, at first, i never thought it was going to work out, but i had no choice than to give it a trial, then i contacted him and he did a spell for me and behold my husband came back on his knees begging to be with me for the rest of his life. i was quite amazed myself with the way the spell work.  I would gladly recommend him for anybody cause he is really powerful and can make things happen. his contact is agbalaxxy@gmail.com


The SublimeAStyleFormatter package works quite well for C, and they also support C++/Java. That one could do the job :)


Holy hell, the reindent function REALLY does not work for JavaScript.

I just added a Key binding:

Preferences -> Key bindings - User

    { "keys": ["command+shift+f"], "command": "reindent"}

and worked, even for Javascript.
@Joe - the problem with reindent is that it doesn't modify spacing for //comments in the code as mentioned above by several others. Having to manually space all of the //comments is far from ideal.
And there is still no code reformat for single line XML and probably HTML.(and the oldest reply is 4 years ago)
(I want to edit the word source list XML file..)
Well I'm going with eclipse for that. There is a tree view, and in source view it formats the single line xml perfectly. The only things I'm having a fuss with for Eclipse is that it doesn't support horizontal scrolling with tilt mouse wheel, and that the search feature isn't that advanced, and the interface isn't that sexy.
Also sublime text doesn't close or suspend unused tabs, at least in version 2, without a plugin. And it's taking 70% of CPU usage and over 1GB of memory.
And it asked for $70 license (although I can use it for free). While Eclipse is completely free and open source
Please just try to improve on those features. It isn't like a software ready for commercial release when it depends on plugins for basic functionality.
And with that $70 licence income you aren't purchasing any plans on userecho, that we can't flag that freaking Cara comment for deletion...(and that comment was there since two years ago...doesn't it shame you, when you can't even delete a spam comment from your product forum)
Can you not be so cheapo like this.
+1 for smarter re-indent. I love ST3 in almost every way and use it for most editing jobs (I also bought a license and still think it was worth every penny). However it's still let down by the Re-Indent function, it isn't smart enough for me to use in alot of cases. Sometimes it just doesn't do anything when there are clearly problems, or when reindenting normal HTML it reindents but doesnt fix the number of spaces / tabs on each line correctly (like when some lines have 2 or 3 spaces or tab characters when you are set to use 4 spaces and no tabs). As far as I'm concerned, this is the only failing of ST - if it could be better I'd be even happier with it.