I am working in cc-mode
in Emacs and I find the indentation very very annoying.
As a VIM user, I'm pretty much used to longer indents, as well as having the luxury of hitting tab to tab as much as I want.
In Emacs, my TAB is mapped to goto-line
. First, which function is designed for indenting the current line (or what's after the point)? indent-region
is annoying since you need to highlight the region.
Second, what's the best way to fix the indentation?
Thank you,
You can see what kind of tabbing is currently in use with M-x describe-variable RET c-indentation-style
(but as the documentation states, don't set this variable directly, instead use M-x c-set-style
).
The variable c-basic-offset
is what controls the tabbing in cc-mode
and its default is set-from-style
which means the tabbing will be inherited from what C style you've set with M-x set-c-style
which will let you choose from a set of built-in styles (see below) or you can create your own style. You can see how the styles are defined with M-x describe-variable RET c-style-alist
and then you can use one of those as a template with M-x c-add-style
.
UPDATE:
Others have suggested using the tab key to insert the \t
tab character, but please don't force insertion of the tab character! As one of the creators of StackOverflow says "only a moron would use tabs to format their code". Now that's a bit harsh, but it's worth noting that even the two most giant rivals, Google and Microsoft, agree on this point (even though they recommend a different number of spaces by default).
Use only spaces, and indent 2 spaces at a time.
Tab characters (\0x09) should not be used in code. All indentation should be done with 4 space characters.
Also, the emacswiki has a section on Tabs are Evil.