What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

After some discussion on this question I decided to make a feature-request (or at least a discussion about it).

It would be very nice to be able to use Tab and Shift+Tab to move code blocks (like in any major IDE).

The most important reason for this request/discussion is that Ctrl+K does not give the desired result/behavior.

Looking forward to your opinions on this.

share|improve this question
3  
Because you are not really supposed to editing code on the site.. Only posting it. Write it and format it in your favorite IDE and just paste it into the post... –  Lix Apr 3 '13 at 13:35
5  
So, it's OK to break normal tabbing in the browser (links, form elements etc)? –  Oded Apr 3 '13 at 13:35
2  
I'm in favor of this. As long as it's only in the question/answer text field. –  mikeTheLiar Apr 3 '13 at 13:35
2  
@Lix What a due respect, but i do spend quite a lot of time on SO editing anwers because people fail to post it correctly.. –  Rob Apr 3 '13 at 13:36
1  
I support this! This is so useful –  Hugo Dozois Apr 3 '13 at 13:38
4  
I'm not dedicated enough to open up an IDE just to fix a random person's code indentation. –  Juhana Apr 3 '13 at 13:39
1  
How about the best of both worlds - have it off by default, but include a checkbox "Allow Tabs to format code". –  acutesoftware Apr 3 '13 at 13:43
11  
No, please don't highjack the tab key. It already has a well-established use in the browser. Fix Ctrl+K and add Ctrl+Shift+K (or other shortcut keys) instead. –  Bill the Lizard Apr 3 '13 at 13:44
1  
@rob - what about using the right (as opposed to left) Ctrl button? That makes it very one-handish :P –  Lix Apr 3 '13 at 13:49
1  
I have a related Feature-Request on MSO: Can we get a button in the post editor to toggle the Tab key being used as 4 Spaces? –  Rachel Apr 3 '13 at 13:50
2  
@rob - tisk tisk... Real programmers never leave the home row ;) –  Lix Apr 3 '13 at 13:51
3  
@hims056 I think it could be better. Press Ctrl + K again to indent more, Ctrl + Shift + K to undo one level of indent. –  Bill the Lizard Apr 3 '13 at 14:07
1  
@BilltheLizard I never use Ctrl+K because I typically have my right hand on my mouse, and my left hand on the left side of the keyboard, while the K key is on the right side of my keyboard. It would be much easier to use if whatever shortcut key is used is on the right side of the keyboard. –  Rachel Apr 3 '13 at 14:14
3  
@Rachel I think they picked Ctrl + K because most of the left-hand keys already have a default shortcut setting in most browsers. If they can find some other shortcut that's not used I'd be fine with it. (Even just adding "indent more" and "indent less" buttons in the formatting row above the editor window would be fine with me. I can use the mouse.) –  Bill the Lizard Apr 3 '13 at 14:22
1  
I'd be down for having a checkbox or a user setting to force it to use the tab key. I'm sure many people like me never use the tab for its default purpose. –  BinaryTox1n Apr 3 '13 at 14:40

2 Answers 2

Though this is not a native StackExchange feature, there's a user script on StackApps that does exactly what you are looking for:

Better handling of indentation and the TAB key when editing posts

This user script changes the behavior of a few keys (most notably the Tab key) within the post editor to behave more like it does in IDEs or text editors:

  • When multiple lines are selected, Tab and Shift-Tab indent and dedent these lines
  • When nothing is selected, Tab and Shift-Tab insert or remove whitespace to align the cursor on a tab boundary
  • When the cursor is within the left margin of a line, Backspace removes whitespace to align the cursor on a tab boundary (in other words, it may delete more than just one space character)
  • On indented lines, the Home key toggles the cursor between the actual beginning of the line and the beginning of the real content (in other words, it jumps back and forth to before and after the leading whitespace). This only happens on lines that are indented by at least four spaces or a tab, since it can be confusing for the following reason: When you press Home in the text editor, you expect the cursor to jump to the beginning of the line as it is displayed, which (due to wrapping) may be different from the actual previous newline character.
  • So you don't have to reach for the mouse to tab out of the editor you can press and release the Ctrl key, and the next key press will not be intercepted; thus Tab takes you out of the editor. Pressing and releasing Ctrl will grey out the text editor until the next keystroke to clarify this. If you think this is too awkward, I'm open to other suggestions, but there should be some way to tab out of the editor .

Note that this will never insert TAB characters, only spaces. It does however handle already-present TABs, and it handles them the same way the Markdown converter does.

share|improve this answer

A "format code" tool would imply

  1. knowing how to format many different languages
  2. picking a indentation style

The first is a hassle, the second an invitation to holy wars.

You shouldn't be typing significant bits of code directly into SO anyway, as you will generate spurious errors: cut and paste the code that you ran to show how it doesn't do what you hoped.

Format in your editor or IDE, already.

share|improve this answer

You must log in to answer this question.

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