+382
Joao Carlos 3 years ago • updated by Kush 1 year ago 54
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)
+6

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... 

+9

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

+1
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.
+4
Lets try and push this so it gets implemented :D
+26
It physically hurts me that this feature is not implemented.
+5
I need this. My JSON data doesn't look up to par.
+1
+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?
+1
Same here would really like this feature.
+5
Y u no fix autofix identation?!
+8
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?
+39
"Edit/Line/Reindent" or "Reindent Lines" in the Command Palette
+3
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.
+7
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.
+1

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.

+5
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.


+3
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!
+3
Yes.  

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.

+1
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.
+12
I think that the Line->Reindent feature does not work vey well also with Javascript.
It would be great to have it fixed
+7
Would be pretty awesome if there was an autoformat like in Netbeans.
+9
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
+1
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.
+2
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. :-/
+2
This really needs work. ERB Support would be awesome!
While it works with 'reindent' I like my array closing bracket under my opening array:
array(
<tap>'somevalue',
);

And not like:

array(
<tap>'somevalue',
<tap>);

Is there a way to change this?

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

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

Time to add this NOW!

+1

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.


https://gist.github.com/3898894


It shells out to Emacs.


I know.

+3

C'mon, when this is comming?

+2

....this absolutely needs to be done.

+2

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.

+6

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

+2

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.

+2

'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.

-2

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.

+5

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.

-31

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

-1

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

+4

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.
+3
@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.