Tabbing your code is really something you want handled by your text editor. What text editor are you using?
Most emacs modes do this automatically. For languages with braces like C++, Perl, or Ruby you just hit tab on any line, and it automatically indents it correctly. For languages like Python tab will cycle through the possible acceptable indentations.
Other text editors like Eclipse (and I believe vi) will indent correctly by default when you hit enter, but after that nothing is automatic. But that's pretty good too.
The problem I have is that I just wrote a bunch of shit in vi (which has not been auto-indenting for me, though I should probably check my .vimrc or whatever), and now I'm editing it using TextMate, and the formatting is all screwed up.
The Python bundle has a nifty "clean up white space" command which in tandem with the "format code" command in the appropriate language bundle works for me.
Eclipse also has a right-click Source->Correct Indentation or Source->Format option for cleaning up code indentation/formatting. I suppose other IDEs and code-oriented editors have something similar.
6 comments
[ 4.8 ms ] story [ 37.1 ms ] threadMost emacs modes do this automatically. For languages with braces like C++, Perl, or Ruby you just hit tab on any line, and it automatically indents it correctly. For languages like Python tab will cycle through the possible acceptable indentations.
Other text editors like Eclipse (and I believe vi) will indent correctly by default when you hit enter, but after that nothing is automatic. But that's pretty good too.
Select a set of lines using:
and then press (for example): to add 2 tabs to the beginning of the selected lines.Or to go the other way (remove 2 tabs):