When writing code in the question/answer editor's code block I believe that it would be extremely useful if we could have the code auto indented instead of being forced to hit space bar multiple times. It would make editing so much faster. Something like:

void myfunk
    int i = 123;^ <-- enter is pressed
    ^             <-- cursor is moved here, spaces are auto-inserted before the cursor

I know there are threads about using the Tab-button and that there are (rightfully) arguments against this behavior since Tab is used for so many other purposes. In the meta question Improvements to editor for formatting source code there are multiple suggestions on stuff to improve. Jon Skeet suggested auto indention and the community seemed to have liked this suggestion. The thread is, however, from 2009 and I thought it was time to make a feature request on the matter.

  • 1
    If you would like to get more attention for that particular question (or one of its answers), a bounty would be the appropriate way.
    – Bart
    Sep 7, 2012 at 8:50
  • @Bart: I hear you. The linked-to question is about tab-indentation whilst this is about auto-indentation. So, its not entirely the same thing even though one of the answers is. That is why I started a new feature-request. Sorry if this is not the correct way to highlight it. I don't know how the "request queue" works, and if a feature-request that hasn't been implemented in 3 years is forgotten or if its considered low priority. I just think this would be a kick-ass feature to have. What is the correct way to proceed, delete this question? Sep 7, 2012 at 13:49
  • Any reason this feature is not being considered for implementation? This is a site for coders after all. Typing code into the editor is a common action. Using an IDE to type in a few lines is not a good substitute. Comparing cost and benefit this feature seems to come out very well. I hereby request it!
    – usr
    Jul 24, 2013 at 13:12
  • How much code are you typing? If it’s a couple lines, how much do you need to indent, exactly? :)
    – Ry-
    Jul 24, 2013 at 15:40
  • 1
    @minitechη I regularly manually fix medium to long, badly idnted blocks of code. This would be very useful for that. Jul 24, 2013 at 17:34
  • 1
    It has been asked why one would need this. You need this once you write a function body, an if, a loop, ... Very common situations.
    – usr
    Jul 25, 2013 at 10:57
  • I don't know whether this is related or not, but I have made a Chrome extension ProKeys that has an option to auto-convert Tab to 4-spaces, this can at least be helpful I believe. Jun 27, 2014 at 11:18

3 Answers 3


In general I would suggest pasting in code copied from your actual development environment and then using the { } button rather than typing code into the Stack Overflow editor whenever you need more than about two lines.

That way you are posting the same code that you tested.

For this reason I consider suggestions that make it easier to type a lot of code into Stack Overflow by hand to be mostly a Bad Thing™.

  • 1
    I think that we should let the community decide if a particular code sample is good or bad. But thanks for the clarification nonetheless. Makes stackoverflowing on the go much harder.
    – basarat
    Apr 9, 2013 at 5:00
  • 7
    Doesn't have to be a lot of code to be useful, even typing 5 lines is tedious right now if you want to have proper indentation. Jul 24, 2013 at 13:17
  • 1
    It would be easier to have this feature for those who are editing an existing code sample with the intention of improving its appearance or making minor changes.
    – ADTC
    Jan 4, 2014 at 20:46
  • Please note that often, questions or answers include (hopefully not more than a few lines of) pseudocode which was never meant to be manifested in any IDE. Or do you have a pseudocode interpreter?
    – Domi
    Jun 18, 2014 at 10:02
  • If we're seriously going to go down that road we should require code to be transcluded from a source repository with continuous compilation. Jun 24, 2014 at 22:13

One quick way to indent code is to paste it into the JavaScript box of JSFiddle and hit Shift+Tab.

I'm not sure if this works for other langauages, and I can't test it (on a mobile), but it's a thought that occured to me.

  • Unless of course you happen to not write Javascript. The general gist of what you are proposing is: Make use of a rich online code editor, such as ACE or CodeMirror (which is what JSFiddle uses), as long as it is not embedded in Stackexchange...
    – Domi
    Jun 18, 2014 at 10:05
  • @Domi I have a feeling JSFiddle just matches on curly braces, but I could be wrong. Jun 18, 2014 at 10:14
  • And Python, Coffee, etc love curly braces so much... Actually, given certain syntax errors (that are correct in another language but incorrect in JS), CodeMirror (when set to JS, such as on JSfiddle) will also refuse to spit out proper indentation.
    – Domi
    Jun 18, 2014 at 10:18

I don't know whether this is related or not, but I have made a Chrome extension ProKeys that has an option to auto-convert Tab to 4-spaces, this can at least be helpful I believe.

  • Community prefer server-side solution, I suppose.
    – Aubin
    Jul 25, 2017 at 9:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .