Home Explore Blog CI



neovim

1st chunk of `runtime/doc/indent.txt`
ba1257c67b2e1791c848755960611e25a6ef6de942c2e0ff0000000100000fa3
*indent.txt*    Nvim


		  VIM REFERENCE MANUAL    by Bram Moolenaar


This file is about indenting C programs and other files.

                                      Type |gO| to see the table of contents.

==============================================================================
1. Indenting C style programs				*C-indenting*

The basics for C style indenting are explained in section |30.2| of the user
manual.

Vim has options for automatically indenting C style program files. Many
programming languages including Java and C++ follow very closely the
formatting conventions established with C.  These options affect only the
indent and do not perform other formatting.  There are additional options that
affect other kinds of formatting as well as indenting, see |format-comments|,
|fo-table|, |gq| and |formatting| for the main ones.

There are in fact four main methods available for indentation, each one
overrides the previous if it is enabled, or non-empty for 'indentexpr':
'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.  One requirement is
that toplevel functions have a "{" in the first column.  Otherwise they are
easily confused with declarations.

These five 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.
'cinscopedecls'	Defines strings that are recognized as a C++ scope declaration.

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.

					*cinkeys-format* *indentkeys-format*
The 'cinkeys' option is a string that controls Vim's indenting in response to
typing certain characters or commands in certain contexts.  Note that this not
only triggers C-indenting.  When 'indentexpr' is not empty 'indentkeys' is
used instead.  The format of 'cinkeys' and 'indentkeys' is equal.

The default is "0{,0},0),0],:,0#,!^F,o,O,e" which specifies that indenting
occurs as follows:

	"0{"	if you type "{" as the first character in a line
	"0}"	if you type "}" as the first character in a line
	"0)"	if you type ")" as the first character in a line
	"0]"	if you type "]" as the first character in a line
	":"	if you type ":" after a label or case statement
	"0#"	if you type "#" as the first character in a line
	"!^F"	if you type CTRL-F (which is not inserted)
	"o"	if you type a <CR> anywhere or use the "o" command (not in
		insert mode!)
	"O"	if you use the "O" command (not in insert mode!)
	"e"	if you type the second 'e' for an "else" at the start of a
		line

Characters that can precede each key:				*i_CTRL-F*
!	When a "!" precedes the key, Vim will not insert the key but will
	instead reindent the current line.  This allows you to define a
	command key for reindenting the current line.  CTRL-F is the default
	key for this.  Be careful if you define CTRL-I for this because CTRL-I
	is the ASCII code for <Tab>.
*	When a "*" precedes the key, Vim will reindent the line before
	inserting the key.  If 'cinkeys' contains "*<Return>", Vim reindents
	the current line before opening a new line.
0	When a zero precedes the key (but appears

Title: Indenting C Style Programs in Vim
Summary
This section of the Vim reference manual discusses options for automatically indenting C style program files, including Java and C++. It covers the 'cindent' option and related settings like 'cinkeys', 'cinoptions', 'cinwords', and 'cinscopedecls'. It also explains how Vim handles indenting with the '=' operator and provides details on the format and usage of the 'cinkeys' option for triggering reindenting in insert mode.