|
|
发表于 2005-10-18 00:05:11
|
显示全部楼层
1. Indenting C programs *C-indenting*
The basics for C indenting are explained in section |30.2| of the user manual.
Vim has options for automatically indenting C program files. These options
affect only the indent and do not perform other formatting. For comment
formatting, see |format-comments|.
Note that this will not work when the |+smartindent| or |+cindent| features
have been disabled at compile time.
There are in fact four methods available for indentation:
'autoindent' uses the indent from the previous line.
'smartindent' is like 'autoindent' but also recognizes some C syntax to
increase/reduce the indent where appropriate.
'cindent' Works more cleverly than the other two and is configurable to
different indenting styles.
'indentexpr' The most flexible of all: Evaluates an expression to compute
the indent of a line. When non-empty this method overrides
the other ones. See |indent-expression|.
The rest of this section describes the 'cindent' option.
Note that 'cindent' indenting does not work for every code scenario. Vim
is not a C compiler: it does not recognize all syntax.
These four options control C program indenting:
'cindent' Enables Vim to perform C program indenting automatically.
'cinkeys' Specifies which keys trigger reindenting in insert mode.
'cinoptions' Sets your preferred indent style.
'cinwords' Defines keywords that start an extra indent in the next line.
If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
Vim's built-in algorithm rather than calling an external program.
See |autocommand| for how to set the 'cindent' option automatically for C code
files and reset it for others. |
|