Could we get a Toggle Button when writing a post that would make it so that the Tab key inserts Space x 4 instead of tabbing out of the TextBox?

There are so many times when I'm writing an answer containing code and would like to indent it correctly, however the tab key leaves the TextBox instead of indenting my typing.

This is even more annoying when writing answers, as the Tab key moves to the "Post Answer" button, and hitting Enter before you notice ends up posting an incomplete answer.

My current workaround is to copy 4 spaces and use Ctrl+V instead of Tab to indent my code as I'm typing it, but this is obnoxious as it requires an extra step, and has to be re-copied anytime I copy/paste anything else. And I'm very forgetful and frequently hit Tab out of habit anyways.

Note that this is not quite a duplicate of Have “Tab” key insert spaces when writing a question or answer as I'm not asking for a universal feature that would prevent keyboard navigation completely, but would instead like an optional toggle button or CheckBox to turn this feature on/off depending on user preference :)

  • I actually do think it's a duplicate, it could be suggested as an answer to that question. – Martijn Pieters Dec 11 '12 at 17:10
  • @MartijnPieters I can't actually post this as an answer to the linked question since it is closed as a duplicate to two other questions, one of which is quite a bit broader than this one, and the other which is asking for something different (indent/outdent buttons on the editor) :) I think this feature request is much more specific to this case only, and should not be closed as a duplicate to that one. – Rachel Dec 11 '12 at 17:12
  • Yick, it is indeed closed. We could re-open it, perhaps? – Martijn Pieters Dec 11 '12 at 17:13
  • @MartijnPieters I'd still prefer my feature request of adding a toggle button to turn this feature on/off instead of reopening an old question asking for this as a universal feature, and posting the Toggle suggestion as an answer, which may or may not get noticed by the SE team that implements feature requests. – Rachel Dec 11 '12 at 17:15
  • 1
    And have Shift + tab remove 4 spaces – Hugo Dozois Apr 3 '13 at 14:02
  • I'm such a dork... but having the tab key not - insert a tab -, or spaces, or whatever.. is literally one of the most excruciating things in my life... I do it so often when posting, I almost give up out of hysteric frustration... It is definitely some space-loving space vs. tabs nazi over at SE that insists on this absolutely stupid behavior. I've used PLENTY of forms / online IDE's that allow you to use the tab as god intended... to insert 4 spaces! – alex gray Oct 2 '13 at 13:32

The easiest solution is to write the code in your editor/IDE of choice - effectively offline and then copy+paste it into the answer box. This works for the following reasons:

  1. You can actually check the code compiles and runs before posting it as an answer.
  2. The editor/IDE will do all the code formatting for you - virtually all languages use 4 spaces these days.
  3. If the formatting isn't 100% correct a quick click of the code button should sort it out.
  • I often don't have an IDE or editor open when I answer SO questions :) – Rachel Jul 22 '14 at 23:17
  • @Rachel: So open Notepad (or any other text editor). :-) – Ken White Jul 23 '14 at 0:50
  • 1
    @KenWhite What you want me to do extra work??? You're crazy... moving mice is hard :) – Rachel Jul 23 '14 at 14:37

They should just add indent/dedent buttons like good editors have, so you can just select and hit the button to move in either direction.


This might make the site harder to use for some people with disabilities and breaks the usability. I understand what you're saying with the whole "tab lock" thing, but that's another level of complexity in both the code and the UI. Suggestion: have Space + Tab = Space x4. To prevent the issue about accidentally posting, maybe go to the 'community wiki' checkbox first? Not the best, but...

Also, one thing I do is type the code out in the editor (ignoring the preview) and then just select all the text and hit the code button. It works fine, and you forget about it.

  • Tab followed by Space? I wonder how one would implement that without breaking the regular use of the Tab key. – Arjan Jun 22 '14 at 21:41
  • @Arjan you're right, the other way would be better. Repeated don't show, so it's just the code that uses repeated spaces, thus probably no one holds down the space bar. – Anonymous Penguin Jun 22 '14 at 21:48
  • That's not a good key combo because it doesn't work lol. Try holding space in the editor: You've just created a space. Try holding tab: you've just exited the editor. Neither of those behaviors can be removed without breaking something very important (regular spaces and tab order). This combination does the trick though. – Viziionary Jun 27 '14 at 19:30

You must log in to answer this question.

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