When editing a question or an answer on StackOverflow, it would be great if, when you are on a line that starts with n ≥ 4 spaces and press Enter, the newly created line would automatically begin with n spaces, and the caret would be at the end of the line.


After having struggled with the Shift+Return approach a few weeks, I have to admit that it is a horrible substitute for real AutoIndent. Two new lines are inserted per Shift+Return, and the indent of the new line is not n spaces (n being the number of spaces of the previous line), but the constant 4. Also, there is an annoying default text; although selected, it is annoying. So I revive this old feature request: I want AutoIndent!

  • What's the plan to escape out of a code block and back into regular text below? For example, if the cursor was in a code block and the user hit enter twice in a row, what would happen?
    – Jon Seigel
    Jul 8, 2010 at 20:48
  • 3
    @Jon Seigel: To get back to normal mode: Press Enter, Enter, Shift+Home, Delete (or BkSp). Jul 8, 2010 at 20:50
  • Sorry, I was being nitpicky. There's no escape condition in the proposal as written. I'd suggest that if the user hits enter on a line with n spaces, but there's nothing else on the line besides the spaces, then the n spaces get removed from the current line, and a newline gets inserted, thus leaving the user at a zero-indent, able to type normal text.
    – Jon Seigel
    Jul 8, 2010 at 20:55
  • @Jon Seigel: Well, sometimes source code does contain empty lines... Jul 8, 2010 at 20:58
  • Ooooh yeah. Good point. I didn't think of that. Hmmm... your key combination would probably be the best solution then.
    – Jon Seigel
    Jul 8, 2010 at 21:02

5 Answers 5


If you are using Chrome here is an extension that adds support for block shifting using tab key and code autoindentation in all textareas plus some more useful features (inspired by Eclipse).

  • +1. I am actually using Chrome, and it appars to work very well. Aug 14, 2010 at 18:33

I don't know if there's just something funny about my setup or if it's already a feature, but if I'm typing code and I press Shift+Enter then I get a new line that's already indented:

so if I type this, then Shift+Enter
I end up on the next line, indented by four space

In fact, when I press Shift+Enter, it indents the line and adds the text "enter code here" and selects that text, so I'm pretty sure it's a feature of the editor and not just something my browser is doing...

  • 1
    Yes, quite true. Works in both Google Chrome and Internet Explorer, so it is definitely a feature at SO. Jul 9, 2010 at 0:14
  • another feature many seem to not know about... is there any list of the shortcuts? Jul 9, 2010 at 4:46
  • @Tobias: let's start a "hidden features of the SO websites" thread :p~ Jul 9, 2010 at 7:31
  • 1
    Oh my god, I spoke too soon. I can't believe it! Jul 9, 2010 at 7:32
  • @Andreas: Shift+Enter doesn't work in Linux :( Aug 14, 2010 at 15:55

This isn't quite what you asked for, but you can get around the problem entirely by using your favourite code editor of choice to write your SO questions and answers (at least if you use Firefox): install the "It's All Text!" extension, which will optionally pop you into your editor to compose any textbox on the page.

You'll never write code directly in your browser again!

PS. vim forever! Death to emacs!

  • It's all text is dead now unfortunately. Have an upvote 'cos vim suxx
    – Joundill
    Aug 24, 2020 at 23:15

This would be a great feature. It would be even better if we could also indent and outdent blocks of code with Tab or Shift+Tab, as seen here: http://teddevito.com/demos/textarea.html

A smart indenter like the one on jsFiddle - it auto indents if you start a block would be cool too, but I think it would be hard to make this language-agnostic.

  • +1: Block indentation adjustment is very important! Aug 14, 2010 at 14:47

The modified wdm.js plugin that was released as open source by the stack overflow team does this already (I use it on my website). It does the same with lists too; if you press enter while in a bullet list the next line will start with "*" automatically.

I'm not really sure why they removed this functionality on stack overflow.

You must log in to answer this question.

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