blob: 5f0893feecf3382c684803a6d2cda9b005856533 [file] [log] [blame]
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +01001*indent.txt* For Vim version 9.1. Last change: 2024 Dec 16
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7This file is about indenting C programs and other files.
8
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000091. Indenting C style programs |C-indenting|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102. Indenting by expression |indent-expression|
11
12==============================================================================
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000131. Indenting C style programs *C-indenting*
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000015The basics for C style indenting are explained in section |30.2| of the user
16manual.
Bram Moolenaar071d4272004-06-13 20:20:40 +000017
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000018Vim has options for automatically indenting C style program files. Many
19programming languages including Java and C++ follow very closely the
20formatting conventions established with C. These options affect only the
21indent and do not perform other formatting. There are additional options that
22affect other kinds of formatting as well as indenting, see |format-comments|,
23|fo-table|, |gq| and |formatting| for the main ones.
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000025There are in fact four main methods available for indentation, each one
26overrides the previous if it is enabled, or non-empty for 'indentexpr':
Bram Moolenaar071d4272004-06-13 20:20:40 +000027'autoindent' uses the indent from the previous line.
28'smartindent' is like 'autoindent' but also recognizes some C syntax to
29 increase/reduce the indent where appropriate.
30'cindent' Works more cleverly than the other two and is configurable to
31 different indenting styles.
32'indentexpr' The most flexible of all: Evaluates an expression to compute
33 the indent of a line. When non-empty this method overrides
34 the other ones. See |indent-expression|.
35The rest of this section describes the 'cindent' option.
36
37Note that 'cindent' indenting does not work for every code scenario. Vim
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +000038is not a C compiler: it does not recognize all syntax. One requirement is
39that toplevel functions have a '{' in the first column. Otherwise they are
40easily confused with declarations.
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
Tom Praschan3506cf32022-04-07 12:39:08 +010042These five options control C program indenting:
Bram Moolenaar071d4272004-06-13 20:20:40 +000043'cindent' Enables Vim to perform C program indenting automatically.
44'cinkeys' Specifies which keys trigger reindenting in insert mode.
45'cinoptions' Sets your preferred indent style.
46'cinwords' Defines keywords that start an extra indent in the next line.
Tom Praschan3506cf32022-04-07 12:39:08 +010047'cinscopedecls' Defines strings that are recognized as a C++ scope declaration.
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
49If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
50Vim's built-in algorithm rather than calling an external program.
51
52See |autocommand| for how to set the 'cindent' option automatically for C code
53files and reset it for others.
54
55 *cinkeys-format* *indentkeys-format*
56The 'cinkeys' option is a string that controls Vim's indenting in response to
57typing certain characters or commands in certain contexts. Note that this not
58only triggers C-indenting. When 'indentexpr' is not empty 'indentkeys' is
59used instead. The format of 'cinkeys' and 'indentkeys' is equal.
60
Bram Moolenaarce655742019-01-31 14:12:57 +010061The default is "0{,0},0),0],:,0#,!^F,o,O,e" which specifies that indenting
62occurs as follows:
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
64 "0{" if you type '{' as the first character in a line
65 "0}" if you type '}' as the first character in a line
66 "0)" if you type ')' as the first character in a line
Bram Moolenaarce655742019-01-31 14:12:57 +010067 "0]" if you type ']' as the first character in a line
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 ":" if you type ':' after a label or case statement
69 "0#" if you type '#' as the first character in a line
70 "!^F" if you type CTRL-F (which is not inserted)
71 "o" if you type a <CR> anywhere or use the "o" command (not in
72 insert mode!)
73 "O" if you use the "O" command (not in insert mode!)
74 "e" if you type the second 'e' for an "else" at the start of a
75 line
76
Bram Moolenaare2f98b92006-03-29 21:18:24 +000077Characters that can precede each key: *i_CTRL-F*
Bram Moolenaar071d4272004-06-13 20:20:40 +000078! When a '!' precedes the key, Vim will not insert the key but will
79 instead reindent the current line. This allows you to define a
80 command key for reindenting the current line. CTRL-F is the default
81 key for this. Be careful if you define CTRL-I for this because CTRL-I
82 is the ASCII code for <Tab>.
83* When a '*' precedes the key, Vim will reindent the line before
84 inserting the key. If 'cinkeys' contains "*<Return>", Vim reindents
85 the current line before opening a new line.
860 When a zero precedes the key (but appears after '!' or '*') Vim will
87 reindent the line only if the key is the first character you type in
88 the line. When used before "=" Vim will only reindent the line if
89 there is only white space before the word.
90
91When neither '!' nor '*' precedes the key, Vim reindents the line after you
92type the key. So ';' sets the indentation of a line which includes the ';'.
93
94Special key names:
95<> Angle brackets mean spelled-out names of keys. For example: "<Up>",
96 "<Ins>" (see |key-notation|).
97^ Letters preceded by a caret (^) are control characters. For example:
98 "^F" is CTRL-F.
99o Reindent a line when you use the "o" command or when Vim opens a new
100 line below the current one (e.g., when you type <Enter> in insert
101 mode).
102O Reindent a line when you use the "O" command.
103e Reindent a line that starts with "else" when you type the second 'e'.
104: Reindent a line when a ':' is typed which is after a label or case
105 statement. Don't reindent for a ":" in "class::method" for C++. To
106 Reindent for any ":", use "<:>".
107=word Reindent when typing the last character of "word". "word" may
108 actually be part of another word. Thus "=end" would cause reindenting
109 when typing the "d" in "endif" or "endwhile". But not when typing
110 "bend". Also reindent when completion produces a word that starts
111 with "word". "0=word" reindents when there is only white space before
112 the word.
113=~word Like =word, but ignore case.
114
115If you really want to reindent when you type 'o', 'O', 'e', '0', '<', '>',
116'*', ':' or '!', use "<o>", "<O>", "<e>", "<0>", "<<>", "<>>", "<*>", "<:>" or
117"<!>", respectively, for those keys.
118
119For an emacs-style indent mode where lines aren't indented every time you
Milly89872f52024-10-05 17:16:18 +0200120press <Enter> but only if you press <Tab>, I suggest: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121 :set cinkeys=0{,0},:,0#,!<Tab>,!^F
122You might also want to switch off 'autoindent' then.
123
124Note: If you change the current line's indentation manually, Vim ignores the
125cindent settings for that line. This prevents vim from reindenting after you
126have changed the indent by typing <BS>, <Tab>, or <Space> in the indent or
127used CTRL-T or CTRL-D.
128
129 *cinoptions-values*
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200130The 'cinoptions' option sets how Vim performs indentation. The value after
131the option character can be one of these (N is any number):
132 N indent N spaces
133 -N indent N spaces to the left
Bram Moolenaar5302d9e2011-09-14 17:55:08 +0200134 Ns N times 'shiftwidth' spaces
135 -Ns N times 'shiftwidth' spaces to the left
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200136
137In the list below,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138"N" represents a number of your choice (the number can be negative). When
139there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
140"1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc. You can use a
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200141decimal point, too: "-0.5s" is minus half a 'shiftwidth'.
142The examples below assume a 'shiftwidth' of 4.
143 *cino->*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144 >N Amount added for "normal" indent. Used after a line that should
145 increase the indent (lines starting with "if", an opening brace,
146 etc.). (default 'shiftwidth').
147
148 cino= cino=>2 cino=>2s >
149 if (cond) if (cond) if (cond)
150 { { {
151 foo; foo; foo;
152 } } }
153<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200154 *cino-e*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155 eN Add N to the prevailing indent inside a set of braces if the
156 opening brace at the End of the line (more precise: is not the
157 first character in a line). This is useful if you want a
158 different indent when the '{' is at the start of the line from
159 when '{' is at the end of the line. (default 0).
160
161 cino= cino=e2 cino=e-2 >
162 if (cond) { if (cond) { if (cond) {
163 foo; foo; foo;
164 } } }
165 else else else
166 { { {
167 bar; bar; bar;
168 } } }
169<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200170 *cino-n*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171 nN Add N to the prevailing indent for a statement after an "if",
172 "while", etc., if it is NOT inside a set of braces. This is
173 useful if you want a different indent when there is no '{'
174 before the statement from when there is a '{' before it.
175 (default 0).
176
177 cino= cino=n2 cino=n-2 >
178 if (cond) if (cond) if (cond)
179 foo; foo; foo;
180 else else else
181 { { {
182 bar; bar; bar;
183 } } }
184<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200185 *cino-f*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186 fN Place the first opening brace of a function or other block in
187 column N. This applies only for an opening brace that is not
188 inside other braces and is at the start of the line. What comes
189 after the brace is put relative to this brace. (default 0).
190
191 cino= cino=f.5s cino=f1s >
192 func() func() func()
193 { { {
194 int foo; int foo; int foo;
195<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200196 *cino-{*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197 {N Place opening braces N characters from the prevailing indent.
198 This applies only for opening braces that are inside other
199 braces. (default 0).
200
201 cino= cino={.5s cino={1s >
202 if (cond) if (cond) if (cond)
203 { { {
204 foo; foo; foo;
205<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200206 *cino-}*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207 }N Place closing braces N characters from the matching opening
208 brace. (default 0).
209
210 cino= cino={2,}-0.5s cino=}2 >
211 if (cond) if (cond) if (cond)
212 { { {
213 foo; foo; foo;
214 } } }
215<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200216 *cino-^*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217 ^N Add N to the prevailing indent inside a set of braces if the
218 opening brace is in column 0. This can specify a different
219 indent for whole of a function (some may like to set it to a
220 negative number). (default 0).
221
222 cino= cino=^-2 cino=^-s >
223 func() func() func()
224 { { {
225 if (cond) if (cond) if (cond)
226 { { {
227 a = b; a = b; a = b;
228 } } }
229 } } }
230<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200231 *cino-L*
Bram Moolenaar02c707a2010-07-17 17:12:06 +0200232 LN Controls placement of jump labels. If N is negative, the label
233 will be placed at column 1. If N is non-negative, the indent of
234 the label will be the prevailing indent minus N. (default -1).
235
236 cino= cino=L2 cino=Ls >
237 func() func() func()
238 { { {
239 { { {
240 stmt; stmt; stmt;
241 LABEL: LABEL: LABEL:
242 } } }
243 } } }
244<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200245 *cino-:*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246 :N Place case labels N characters from the indent of the switch().
247 (default 'shiftwidth').
248
249 cino= cino=:0 >
250 switch (x) switch(x)
251 { {
252 case 1: case 1:
253 a = b; a = b;
254 default: default:
255 } }
256<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200257 *cino-=*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258 =N Place statements occurring after a case label N characters from
259 the indent of the label. (default 'shiftwidth').
260
261 cino= cino==10 >
262 case 11: case 11: a = a + 1;
263 a = a + 1; b = b + 1;
264<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200265 *cino-l*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266 lN If N != 0 Vim will align with a case label instead of the
267 statement after it in the same line.
268
269 cino= cino=l1 >
270 switch (a) { switch (a) {
271 case 1: { case 1: {
272 break; break;
273 } }
274<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200275 *cino-b*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 bN If N != 0 Vim will align a final "break" with the case label,
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000277 so that case..break looks like a sort of block. (default: 0).
Bram Moolenaar81af9252010-12-10 20:35:50 +0100278 When using 1, consider adding "0=break" to 'cinkeys'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279
280 cino= cino=b1 >
281 switch (x) switch(x)
282 { {
283 case 1: case 1:
284 a = b; a = b;
285 break; break;
286
287 default: default:
288 a = 0; a = 0;
289 break; break;
290 } }
291<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200292 *cino-g*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000293 gN Place C++ scope declarations N characters from the indent of the
Bram Moolenaar8a3b8052022-06-26 12:21:15 +0100294 block they are in. (default 'shiftwidth'). By default, a scope
Tom Praschan3506cf32022-04-07 12:39:08 +0100295 declaration is "public:", "protected:" or "private:". This can
296 be adjusted with the 'cinscopedecls' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000297
298 cino= cino=g0 >
299 { {
300 public: public:
301 a = b; a = b;
302 private: private:
303 } }
304<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200305 *cino-h*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306 hN Place statements occurring after a C++ scope declaration N
307 characters from the indent of the label. (default
308 'shiftwidth').
309
310 cino= cino=h10 >
311 public: public: a = a + 1;
312 a = a + 1; b = b + 1;
313<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200314 *cino-N*
315 NN Indent inside C++ namespace N characters extra compared to a
316 normal block. (default 0).
317
318 cino= cino=N-s >
319 namespace { namespace {
320 void function(); void function();
321 } }
322
323 namespace my namespace my
324 { {
325 void function(); void function();
326 } }
327<
Bram Moolenaar7720ba82017-03-08 22:19:26 +0100328 *cino-E*
329 EN Indent inside C++ linkage specifications (extern "C" or
330 extern "C++") N characters extra compared to a normal block.
331 (default 0).
332
333 cino= cino=E-s >
334 extern "C" { extern "C" {
335 void function(); void function();
336 } }
337
338 extern "C" extern "C"
339 { {
340 void function(); void function();
341 } }
342<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200343 *cino-p*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344 pN Parameter declarations for K&R-style function declarations will
345 be indented N characters from the margin. (default
346 'shiftwidth').
347
348 cino= cino=p0 cino=p2s >
349 func(a, b) func(a, b) func(a, b)
350 int a; int a; int a;
351 char b; char b; char b;
352<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200353 *cino-t*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354 tN Indent a function return type declaration N characters from the
355 margin. (default 'shiftwidth').
356
357 cino= cino=t0 cino=t7 >
358 int int int
359 func() func() func()
360<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200361 *cino-i*
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000362 iN Indent C++ base class declarations and constructor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363 initializations, if they start in a new line (otherwise they
364 are aligned at the right side of the ':').
365 (default 'shiftwidth').
366
367 cino= cino=i0 >
368 class MyClass : class MyClass :
369 public BaseClass public BaseClass
370 {} {}
371 MyClass::MyClass() : MyClass::MyClass() :
372 BaseClass(3) BaseClass(3)
373 {} {}
374<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200375 *cino-+*
Bram Moolenaar662db672011-03-22 14:05:35 +0100376 +N Indent a continuation line (a line that spills onto the next)
377 inside a function N additional characters. (default
378 'shiftwidth').
379 Outside of a function, when the previous line ended in a
380 backslash, the 2 * N is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381
382 cino= cino=+10 >
383 a = b + 9 * a = b + 9 *
384 c; c;
385<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200386 *cino-c*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387 cN Indent comment lines after the comment opener, when there is no
388 other text with which to align, N characters from the comment
389 opener. (default 3). See also |format-comments|.
390
391 cino= cino=c5 >
392 /* /*
393 text. text.
394 */ */
395<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200396 *cino-C*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397 CN When N is non-zero, indent comment lines by the amount specified
398 with the c flag above even if there is other text behind the
399 comment opener. (default 0).
400
401 cino=c0 cino=c0,C1 >
402 /******** /********
403 text. text.
404 ********/ ********/
405< (Example uses ":set comments& comments-=s1:/* comments^=s0:/*")
406
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200407 *cino-/*
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000408 /N Indent comment lines N characters extra. (default 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409 cino= cino=/4 >
410 a = b; a = b;
411 /* comment */ /* comment */
412 c = d; c = d;
413<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200414 *cino-(*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415 (N When in unclosed parentheses, indent N characters from the line
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200416 with the unclosed parenthesis. Add a 'shiftwidth' for every
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +0200417 extra unclosed parentheses. When N is 0 or the unclosed
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200418 parenthesis is the first non-white character in its line, line
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +0200419 up with the next non-white character after the unclosed
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200420 parenthesis. (default 'shiftwidth' * 2).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000421
422 cino= cino=(0 >
423 if (c1 && (c2 || if (c1 && (c2 ||
424 c3)) c3))
425 foo; foo;
426 if (c1 && if (c1 &&
427 (c2 || c3)) (c2 || c3))
428 { {
429<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200430 *cino-u*
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +0200431 uN Same as (N, but for one nesting level deeper.
432 (default 'shiftwidth').
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433
434 cino= cino=u2 >
435 if (c123456789 if (c123456789
436 && (c22345 && (c22345
437 || c3)) || c3))
438<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200439 *cino-U*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 UN When N is non-zero, do not ignore the indenting specified by
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200441 ( or u in case that the unclosed parenthesis is the first
Bram Moolenaar071d4272004-06-13 20:20:40 +0000442 non-white character in its line. (default 0).
443
444 cino= or cino=(s cino=(s,U1 >
445 c = c1 && c = c1 &&
446 ( (
447 c2 || c2 ||
448 c3 c3
449 ) && c4; ) && c4;
450<
Bram Moolenaar5302d9e2011-09-14 17:55:08 +0200451 *cino-w*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452 wN When in unclosed parentheses and N is non-zero and either
453 using "(0" or "u0", respectively, or using "U0" and the unclosed
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200454 parenthesis is the first non-white character in its line, line
455 up with the character immediately after the unclosed parenthesis
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456 rather than the first non-white character. (default 0).
457
458 cino=(0 cino=(0,w1 >
459 if ( c1 if ( c1
460 && ( c2 && ( c2
461 || c3)) || c3))
462 foo; foo;
463<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200464 *cino-W*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465 WN When in unclosed parentheses and N is non-zero and either
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200466 using "(0" or "u0", respectively and the unclosed parenthesis is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467 the last non-white character in its line and it is not the
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200468 closing parenthesis, indent the following line N characters
Bram Moolenaar071d4272004-06-13 20:20:40 +0000469 relative to the outer context (i.e. start of the line or the
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200470 next unclosed parenthesis). (default: 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000471
472 cino=(0 cino=(0,W4 >
473 a_long_line( a_long_line(
474 argument, argument,
475 argument); argument);
476 a_short_line(argument, a_short_line(argument,
477 argument); argument);
478<
Bram Moolenaar3675fa02012-04-05 17:17:42 +0200479 *cino-k*
480 kN When in unclosed parentheses which follow "if", "for" or
481 "while" and N is non-zero, overrides the behaviour defined by
482 "(N": causes the indent to be N characters relative to the outer
483 context (i.e. the line where "if", "for" or "while" is). Has
484 no effect on deeper levels of nesting. Affects flags like "wN"
485 only for the "if", "for" and "while" conditions. If 0, defaults
486 to behaviour defined by the "(N" flag. (default: 0).
487
488 cino=(0 cino=(0,ks >
489 if (condition1 if (condition1
490 && condition2) && condition2)
491 action(); action();
492 function(argument1 function(argument1
493 && argument2); && argument2);
494<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200495 *cino-m*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496 mN When N is non-zero, line up a line starting with a closing
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200497 parenthesis with the first character of the line with the
498 matching opening parenthesis. (default 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499
500 cino=(s cino=(s,m1 >
501 c = c1 && ( c = c1 && (
502 c2 || c2 ||
503 c3 c3
504 ) && c4; ) && c4;
505 if ( if (
506 c1 && c2 c1 && c2
507 ) )
508 foo; foo;
509<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200510 *cino-M*
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000511 MN When N is non-zero, line up a line starting with a closing
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200512 parenthesis with the first character of the previous line.
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000513 (default 0).
514
515 cino= cino=M1 >
516 if (cond1 && if (cond1 &&
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000517 cond2 cond2
518 ) )
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000519<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200520 *java-cinoptions* *java-indenting* *cino-j*
Bram Moolenaar97293012011-07-18 19:40:27 +0200521 jN Indent Java anonymous classes correctly. Also works well for
522 Javascript. The value 'N' is currently unused but must be
523 non-zero (e.g. 'j1'). 'j1' will indent for example the
524 following code snippet correctly: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525
526 object.add(new ChangeListener() {
527 public void stateChanged(ChangeEvent e) {
528 do_something();
529 }
530 });
531<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200532 *javascript-cinoptions* *javascript-indenting* *cino-J*
Bram Moolenaar3acfc302010-07-11 17:23:02 +0200533 JN Indent JavaScript object declarations correctly by not confusing
Bram Moolenaar664f3cf2019-12-07 16:03:51 +0100534 them with labels. The value 'N' is currently unused but must be
Bram Moolenaar97293012011-07-18 19:40:27 +0200535 non-zero (e.g. 'J1'). If you enable this you probably also want
536 to set |cino-j|. >
Bram Moolenaar3acfc302010-07-11 17:23:02 +0200537
538 var bar = {
539 foo: {
540 that: this,
541 some: ok,
542 },
Bram Moolenaar664f3cf2019-12-07 16:03:51 +0100543 "bar":{
Bram Moolenaar3acfc302010-07-11 17:23:02 +0200544 a : 2,
545 b: "123abc",
546 x: 4,
547 "y": 5
548 }
549 }
550<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200551 *cino-)*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 )N Vim searches for unclosed parentheses at most N lines away.
553 This limits the time needed to search for parentheses. (default
554 20 lines).
555
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200556 *cino-star*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 *N Vim searches for unclosed comments at most N lines away. This
558 limits the time needed to search for the start of a comment.
Bram Moolenaard09acef2012-09-21 14:54:30 +0200559 If your /* */ comments stop indenting after N lines this is the
Bram Moolenaar8e5af3e2011-04-28 19:02:44 +0200560 value you will want to change.
Bram Moolenaar6dfc28b2010-02-11 14:19:15 +0100561 (default 70 lines).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200563 *cino-#*
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +0100564 #N When N is non-zero recognize shell/Perl comments starting with
565 '#', do not recognize preprocessor lines; allow right-shifting
566 lines that start with "#".
567 When N is zero (default): don't recognize '#' comments, do
568 recognize preprocessor lines; right-shifting lines that start
569 with "#" does not work.
Bram Moolenaar39353fd2007-03-27 09:02:11 +0000570
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200571 *cino-P*
Bram Moolenaard881b512020-05-31 17:49:30 +0200572 PN When N is non-zero recognize C pragmas, and indent them like any
573 other code; does not concern other preprocessor directives.
574 When N is zero (default): don't recognize C pragmas, treating
575 them like every other preprocessor directive.
576
577
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578The defaults, spelled out in full, are:
Bram Moolenaar7720ba82017-03-08 22:19:26 +0100579 cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,E0,ps,ts,is,+s,
Bram Moolenaard881b512020-05-31 17:49:30 +0200580 c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0,P0
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581
582Vim puts a line in column 1 if:
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +0100583- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584- It starts with a label (a keyword followed by ':', other than "case" and
Bram Moolenaar02c707a2010-07-17 17:12:06 +0200585 "default") and 'cinoptions' does not contain an 'L' entry with a positive
586 value.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587- Any combination of indentations causes the line to have less than 0
588 indentation.
589
590==============================================================================
5912. Indenting by expression *indent-expression*
592
593The basics for using flexible indenting are explained in section |30.3| of the
594user manual.
595
596If you want to write your own indent file, it must set the 'indentexpr'
Bram Moolenaarba3ff532018-11-04 14:45:49 +0100597option. Setting the 'indentkeys' option is often useful.
598See the $VIMRUNTIME/indent/README.txt file for hints.
599See the $VIMRUNTIME/indent directory for examples.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600
601
602REMARKS ABOUT SPECIFIC INDENT FILES ~
603
604
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100605CLOJURE *ft-clojure-indent* *clojure-indent*
606
607Clojure indentation differs somewhat from traditional Lisps, due in part to
608the use of square and curly brackets, and otherwise by community convention.
Bram Moolenaarbaca7f72013-09-22 14:42:24 +0200609These conventions are not universally followed, so the Clojure indent script
Bram Moolenaar113cb512021-11-07 20:27:04 +0000610offers a few configuration options.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100611
Bram Moolenaar113cb512021-11-07 20:27:04 +0000612(If the current Vim does not include |searchpairpos()|, the indent script falls
613back to normal 'lisp' indenting, and the following options are ignored.)
614
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100615
616 *g:clojure_maxlines*
617
Bram Moolenaar113cb512021-11-07 20:27:04 +0000618Sets maximum scan distance of `searchpairpos()`. Larger values trade
619performance for correctness when dealing with very long forms. A value of
6200 will scan without limits. The default is 300.
621
622
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100623 *g:clojure_fuzzy_indent*
624 *g:clojure_fuzzy_indent_patterns*
625 *g:clojure_fuzzy_indent_blacklist*
626
627The 'lispwords' option is a list of comma-separated words that mark special
Bram Moolenaar113cb512021-11-07 20:27:04 +0000628forms whose subforms should be indented with two spaces.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100629
630For example:
631>
632 (defn bad []
633 "Incorrect indentation")
634
635 (defn good []
636 "Correct indentation")
637<
638If you would like to specify 'lispwords' with a |pattern| instead, you can use
639the fuzzy indent feature:
640>
641 " Default
642 let g:clojure_fuzzy_indent = 1
643 let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let']
644 let g:clojure_fuzzy_indent_blacklist =
645 \ ['-fn$', '\v^with-%(meta|out-str|loading-context)$']
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100646<
647|g:clojure_fuzzy_indent_patterns| and |g:clojure_fuzzy_indent_blacklist| are
Bram Moolenaar113cb512021-11-07 20:27:04 +0000648lists of patterns that will be matched against the unqualified symbol at the
649head of a list. This means that a pattern like `"^foo"` will match all these
650candidates: `foobar`, `my.ns/foobar`, and `#'foobar`.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100651
652Each candidate word is tested for special treatment in this order:
653
654 1. Return true if word is literally in 'lispwords'
655 2. Return false if word matches a pattern in
656 |g:clojure_fuzzy_indent_blacklist|
657 3. Return true if word matches a pattern in
658 |g:clojure_fuzzy_indent_patterns|
659 4. Return false and indent normally otherwise
660
Bram Moolenaar113cb512021-11-07 20:27:04 +0000661
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100662 *g:clojure_special_indent_words*
663
Bram Moolenaar113cb512021-11-07 20:27:04 +0000664Some forms in Clojure are indented such that every subform is indented by only
665two spaces, regardless of 'lispwords'. If you have a custom construct that
666should be indented in this idiosyncratic fashion, you can add your symbols to
667the default list below.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100668>
669 " Default
670 let g:clojure_special_indent_words =
671 \ 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
672<
Bram Moolenaar113cb512021-11-07 20:27:04 +0000673
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100674 *g:clojure_align_multiline_strings*
675
Bram Moolenaar113cb512021-11-07 20:27:04 +0000676Align subsequent lines in multi-line strings to the column after the opening
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100677quote, instead of the same column.
678
679For example:
680>
681 (def default
682 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
683 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
684 enim ad minim veniam, quis nostrud exercitation ullamco laboris
685 nisi ut aliquip ex ea commodo consequat.")
686
687 (def aligned
688 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
689 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
690 enim ad minim veniam, quis nostrud exercitation ullamco laboris
691 nisi ut aliquip ex ea commodo consequat.")
692<
Bram Moolenaar113cb512021-11-07 20:27:04 +0000693
Bram Moolenaar438f67a2014-01-07 06:09:28 +0100694 *g:clojure_align_subforms*
695
696By default, parenthesized compound forms that look like function calls and
697whose head subform is on its own line have subsequent subforms indented by
698two spaces relative to the opening paren:
699>
700 (foo
701 bar
702 baz)
703<
Bram Moolenaar113cb512021-11-07 20:27:04 +0000704Setting this option to `1` changes this behaviour so that all subforms are
705aligned to the same column, emulating the default behaviour of
706clojure-mode.el:
Bram Moolenaar438f67a2014-01-07 06:09:28 +0100707>
708 (foo
709 bar
710 baz)
711<
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100712
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000713FORTRAN *ft-fortran-indent*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714
Ajit-Thakkard96f25b2023-12-29 11:29:43 -0400715Block if, select case, select type, select rank, where, forall, type,
716interface, associate, block, enum, critical, and change team constructs are
717indented. The indenting of subroutines, functions, modules, and program blocks
718is optional. Comments, labeled statements, and continuation lines are indented
719if the Fortran is in free source form, whereas they are not indented if the
720Fortran is in fixed source form because of the left margin requirements. Hence
721manual indent corrections will be necessary for labeled statements and
722continuation lines when fixed source form is being used. For further
723discussion of the method used for the detection of source format see
724|ft-fortran-syntax|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725
726Do loops ~
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000727All do loops are left unindented by default. Do loops can be unstructured in
Ajit-Thakkar68630842023-12-05 23:07:27 +0100728Fortran with (possibly multiple) loops ending on a labeled executable
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000729statement of almost arbitrary type. Correct indentation requires
Ajit-Thakkar68630842023-12-05 23:07:27 +0100730compiler-quality parsing. Old code with do loops ending on labeled statements
731of arbitrary type can be indented with elaborate programs such as Tidy.
732Structured do/continue loops are also left unindented because continue
733statements are used for purposes other than ending a do loop. Programs such
734as Tidy can convert structured do/continue loops to the do/enddo form. Do
735loops of the do/enddo variety can be indented. If you use only structured
736loops of the do/enddo form, you should declare this by setting the
737fortran_do_enddo variable in your .vimrc as follows >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738
739 let fortran_do_enddo=1
740
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000741in which case do loops will be indented. If all your loops are of do/enddo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742type only in, say, .f90 files, then you should set a buffer flag with an
743autocommand such as >
744
745 au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1
746
747to get do loops indented in .f90 files and left alone in Fortran files with
748other extensions such as .for.
749
Bram Moolenaar251e1912011-06-19 05:09:16 +0200750Program units ~
Ajit-Thakkar68630842023-12-05 23:07:27 +0100751Indenting of program units (subroutines, functions, modules, and program
752blocks) can be increased by setting the variable fortran_indent_more and can
753be decreased by setting the variable fortran_indent_less. These variables
754can be set for all fortran files in your .vimrc as follows >
Bram Moolenaar251e1912011-06-19 05:09:16 +0200755
756 let fortran_indent_less=1
757
Ajit-Thakkar68630842023-12-05 23:07:27 +0100758A finer level of control can be achieved by setting the corresponding
Bram Moolenaar251e1912011-06-19 05:09:16 +0200759buffer-local variable as follows >
760
761 let b:fortran_indent_less=1
762
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200764HTML *ft-html-indent* *html-indent* *html-indenting*
765
766This is about variables you can set in your vimrc to customize HTML indenting.
767
768You can set the indent for the first line after <script> and <style>
769"blocktags" (default "zero"): >
770
771 :let g:html_indent_script1 = "inc"
772 :let g:html_indent_style1 = "inc"
773<
774 VALUE MEANING ~
775 "zero" zero indent
776 "auto" auto indent (same indent as the blocktag)
777 "inc" auto indent + one indent step
778
Bram Moolenaarc4573eb2022-01-31 15:40:56 +0000779You can set the indent for attributes after an open <tag line: >
780
781 :let g:html_indent_attribute = 1
782<
783 VALUE MEANING ~
784 1 auto indent, one indent step more than <tag
785 2 auto indent, two indent steps (default)
786 > 2 auto indent, more indent steps
787
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200788Many tags increase the indent for what follows per default (see "Add Indent
Bram Moolenaar52b91d82013-06-15 21:39:51 +0200789Tags" in the script). You can add further tags with: >
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200790
791 :let g:html_indent_inctags = "html,body,head,tbody"
792
793You can also remove such tags with: >
794
795 :let g:html_indent_autotags = "th,td,tr,tfoot,thead"
796
797Default value is empty for both variables. Note: the initial "inctags" are
798only defined once per Vim session.
799
800User variables are only read when the script is sourced. To enable your
Bram Moolenaar52b91d82013-06-15 21:39:51 +0200801changes during a session, without reloading the HTML file, you can manually
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200802do: >
803
804 :call HtmlIndent_CheckUserSettings()
805
806Detail:
807 Calculation of indent inside "blocktags" with "alien" content:
808 BLOCKTAG INDENT EXPR WHEN APPLICABLE ~
Bram Moolenaar52b91d82013-06-15 21:39:51 +0200809 <script> : {customizable} if first line of block
810 : cindent(v:lnum) if attributes empty or contain "java"
811 : -1 else (vbscript, tcl, ...)
812 <style> : {customizable} if first line of block
813 : GetCSSIndent() else
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200814 <!-- --> : -1
815
Serhii Khoma5ca8f222024-11-12 21:49:42 +0100816IDRIS2 *ft-idris2-indent*
817
818Idris 2 indentation can be configured with several variables that control the
819indentation level for different language constructs:
820
821The "g:idris2_indent_if" variable controls the indentation of `then` and `else`
822blocks after `if` statements. Defaults to 3.
823
824The "g:idris2_indent_case" variable controls the indentation of patterns in
825`case` expressions. Defaults to 5.
826
827The "g:idris2_indent_let" variable controls the indentation after `let`
828bindings. Defaults to 4.
829
830The "g:idris2_indent_rewrite" variable controls the indentation after `rewrite`
831expressions. Defaults to 8.
832
833The "g:idris2_indent_where" variable controls the indentation of `where`
834blocks. Defaults to 6.
835
836The "g:idris2_indent_do" variable controls the indentation in `do` blocks.
837Defaults to 3.
838
839Example configuration: >
840
841 let g:idris2_indent_if = 2
842 let g:idris2_indent_case = 4
843 let g:idris2_indent_let = 4
844 let g:idris2_indent_rewrite = 8
845 let g:idris2_indent_where = 6
846 let g:idris2_indent_do = 3
847<
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200848
Bram Moolenaar32b364f2019-12-08 15:07:48 +0100849MATLAB *ft-matlab-indent* *matlab-indent* *matlab-indenting*
850
851The setting Function indenting format in MATLAB Editor/Debugger Language
852Preferences corresponds to: >
853 :let g:MATLAB_function_indent = {0, 1 or 2 (default)}
854
855Where 0 is for Classic, 1 for Indent nested functions and 2 for Indent all
856functions.
857
858
Bram Moolenaarc236c162008-07-13 17:41:49 +0000859PHP *ft-php-indent* *php-indent* *php-indenting*
860
861NOTE: PHP files will be indented correctly only if PHP |syntax| is active.
862
863If you are editing a file in Unix 'fileformat' and '\r' characters are present
864before new lines, indentation won't proceed correctly ; you have to remove
865those useless characters first with a command like: >
866
867 :%s /\r$//g
868
869Or, you can simply |:let| the variable PHP_removeCRwhenUnix to 1 and the
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200870script will silently remove them when Vim loads a PHP file (at each |BufRead|).
Bram Moolenaarc236c162008-07-13 17:41:49 +0000871
872OPTIONS: ~
873
874PHP indenting can be altered in several ways by modifying the values of some
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875global variables:
Bram Moolenaarc236c162008-07-13 17:41:49 +0000876
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200877 *php-comment* *PHP_autoformatcomment*
Bram Moolenaar088e8e32019-08-08 22:15:18 +0200878To not enable auto-formatting of comments by default (if you want to use your
Bram Moolenaarc236c162008-07-13 17:41:49 +0000879own 'formatoptions'): >
880 :let g:PHP_autoformatcomment = 0
881
882Else, 't' will be removed from the 'formatoptions' string and "qrowcb" will be
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200883added, see |fo-table| for more information.
Bram Moolenaarc236c162008-07-13 17:41:49 +0000884-------------
885
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200886 *PHP_outdentSLComments*
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200887To add extra indentation to single-line comments: >
888 :let g:PHP_outdentSLComments = N
889
890With N being the number of 'shiftwidth' to add.
891
892Only single-line comments will be affected such as: >
893 # Comment
894 // Comment
895 /* Comment */
896-------------
897
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200898 *PHP_default_indenting*
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200899To add extra indentation to every PHP lines with N being the number of
Bram Moolenaarc236c162008-07-13 17:41:49 +0000900'shiftwidth' to add: >
901 :let g:PHP_default_indenting = N
902
903For example, with N = 1, this will give:
904>
905 <?php
906 if (!isset($History_lst_sel))
907 if (!isset($History_lst_sel))
908 if (!isset($History_lst_sel)) {
909 $History_lst_sel=0;
910 } else
911 $foo="bar";
912
913 $command_hist = TRUE;
914 ?>
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200915(Notice the extra indentation between the PHP container markers and the code)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000916-------------
917
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200918 *PHP_outdentphpescape*
919To indent PHP escape tags as the surrounding non-PHP code (only affects the
920PHP escape tags): >
Bram Moolenaar2f0936c2022-01-08 21:51:59 +0000921 :let g:PHP_outdentphpescape = 0
Bram Moolenaar8408a9a2010-07-30 22:41:22 +0200922-------------
923
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200924 *PHP_removeCRwhenUnix*
Bram Moolenaarc236c162008-07-13 17:41:49 +0000925To automatically remove '\r' characters when the 'fileformat' is set to Unix: >
926 :let g:PHP_removeCRwhenUnix = 1
927-------------
928
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200929 *PHP_BracesAtCodeLevel*
Bram Moolenaarc236c162008-07-13 17:41:49 +0000930To indent braces at the same level than the code they contain: >
931 :let g:PHP_BracesAtCodeLevel = 1
Bram Moolenaar664f3cf2019-12-07 16:03:51 +0100932
Bram Moolenaarc236c162008-07-13 17:41:49 +0000933This will give the following result: >
934 if ($foo)
935 {
936 foo();
937 }
938Instead of: >
939 if ($foo)
940 {
941 foo();
942 }
943
944NOTE: Indenting will be a bit slower if this option is used because some
945 optimizations won't be available.
946-------------
947
Bram Moolenaar54775062019-07-31 21:07:14 +0200948 *PHP_vintage_case_default_indent*
Bram Moolenaarc236c162008-07-13 17:41:49 +0000949To indent 'case:' and 'default:' statements in switch() blocks: >
950 :let g:PHP_vintage_case_default_indent = 1
951
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200952In PHP braces are not required inside 'case/default' blocks therefore 'case:'
953and 'default:' are indented at the same level than the 'switch()' to avoid
954meaningless indentation. You can use the above option to return to the
955traditional way.
Bram Moolenaar0b0f0992018-05-22 21:41:30 +0200956-------------
957
958 *PHP_noArrowMatching*
959By default the indent script will indent multi-line chained calls by matching
960the position of the '->': >
961
962 $user_name_very_long->name()
963 ->age()
964 ->info();
965
966You can revert to the classic way of indenting by setting this option to 1: >
967 :let g:PHP_noArrowMatching = 1
968
969You will obtain the following result: >
970
971 $user_name_very_long->name()
972 ->age()
973 ->info();
974
Bram Moolenaar54775062019-07-31 21:07:14 +0200975-------------
976
977 *PHP_IndentFunctionCallParameters*
978Extra indentation levels to add to parameters in multi-line function calls. >
979 let g:PHP_IndentFunctionCallParameters = 1
980
981Function call arguments will indent 1 extra level. For two-space indentation: >
982
983 function call_the_thing(
984 $with_this,
985 $and_that
986 ) {
987 $this->do_the_thing(
988 $with_this,
989 $and_that
990 );
991 }
992
993-------------
994
995 *PHP_IndentFunctionDeclarationParameters*
Bram Moolenaar2e693a82019-10-16 22:35:02 +0200996Extra indentation levels to add to arguments in multi-line function
997definitions. >
Bram Moolenaar54775062019-07-31 21:07:14 +0200998 let g:PHP_IndentFunctionDeclarationParameters = 1
999
Bram Moolenaar2e693a82019-10-16 22:35:02 +02001000Function arguments in declarations will indent 1 extra level. For two-space
1001indentation: >
Bram Moolenaar54775062019-07-31 21:07:14 +02001002
1003 function call_the_thing(
1004 $with_this,
1005 $and_that
1006 ) {
1007 $this->do_the_thing(
1008 $with_this,
1009 $and_that
1010 );
1011 }
Bram Moolenaarc236c162008-07-13 17:41:49 +00001012
1013
Bram Moolenaarda2303d2005-08-30 21:55:26 +00001014PYTHON *ft-python-indent*
Bram Moolenaar05159a02005-02-26 23:04:13 +00001015
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001016The amount of indent can be set with the `g:python_indent` |Dictionary|, which
1017needs to be created before adding the items: >
1018 let g:python_indent = {}
1019The examples given are the defaults. Note that the dictionary values are set
1020to an expression, so that you can change the value of 'shiftwidth' later
1021without having to update these values.
Bram Moolenaar05159a02005-02-26 23:04:13 +00001022
1023Indent after an open paren: >
Bram Moolenaarfd999452022-08-24 18:30:14 +01001024 let g:python_indent.open_paren = 'shiftwidth() * 2'
Bram Moolenaar05159a02005-02-26 23:04:13 +00001025Indent after a nested paren: >
Bram Moolenaarfd999452022-08-24 18:30:14 +01001026 let g:python_indent.nested_paren = 'shiftwidth()'
Bram Moolenaar05159a02005-02-26 23:04:13 +00001027Indent for a continuation line: >
Bram Moolenaarfd999452022-08-24 18:30:14 +01001028 let g:python_indent.continue = 'shiftwidth() * 2'
1029
1030By default, the closing paren on a multiline construct lines up under the first
1031non-whitespace character of the previous line.
1032If you prefer that it's lined up under the first character of the line that
1033starts the multiline construct, reset this key: >
1034 let g:python_indent.closed_paren_align_last_line = v:false
Bram Moolenaar05159a02005-02-26 23:04:13 +00001035
Bram Moolenaare7b1ea02020-08-07 19:54:59 +02001036The method uses |searchpair()| to look back for unclosed parentheses. This
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01001037can sometimes be slow, thus it timeouts after 150 msec. If you notice the
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02001038indenting isn't correct, you can set a larger timeout in msec: >
Bram Moolenaarfd999452022-08-24 18:30:14 +01001039 let g:python_indent.searchpair_timeout = 500
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02001040
Bram Moolenaarf6b40102019-02-22 15:24:03 +01001041If looking back for unclosed parenthesis is still too slow, especially during
1042a copy-paste operation, or if you don't need indenting inside multi-line
1043parentheses, you can completely disable this feature: >
Bram Moolenaarfd999452022-08-24 18:30:14 +01001044 let g:python_indent.disable_parentheses_indenting = 1
1045
1046For backward compatibility, these variables are also supported: >
1047 g:pyindent_open_paren
1048 g:pyindent_nested_paren
1049 g:pyindent_continue
1050 g:pyindent_searchpair_timeout
1051 g:pyindent_disable_parentheses_indenting
Bram Moolenaarf6b40102019-02-22 15:24:03 +01001052
Bram Moolenaar05159a02005-02-26 23:04:13 +00001053
Bram Moolenaar5302d9e2011-09-14 17:55:08 +02001054R *ft-r-indent*
1055
1056Function arguments are aligned if they span for multiple lines. If you prefer
1057do not have the arguments of functions aligned, put in your |vimrc|:
1058>
1059 let r_indent_align_args = 0
1060<
1061All lines beginning with a comment character, #, get the same indentation
1062level of the normal R code. Users of Emacs/ESS may be used to have lines
1063beginning with a single # indented in the 40th column, ## indented as R code,
1064and ### not indented. If you prefer that lines beginning with comment
1065characters are aligned as they are by Emacs/ESS, put in your |vimrc|:
1066>
1067 let r_indent_ess_comments = 1
1068<
1069If you prefer that lines beginning with a single # are aligned at a column
1070different from the 40th one, you should set a new value to the variable
1071r_indent_comment_column, as in the example below:
1072>
1073 let r_indent_comment_column = 30
1074<
1075Any code after a line that ends with "<-" is indented. Emacs/ESS does not
Jakson Alves de Aquino9042bd82023-12-25 09:22:27 +00001076indent the code if it is a top-level function. If you prefer a behavior like
1077Emacs/ESS one in this regard, put in your |vimrc|:
Bram Moolenaar5302d9e2011-09-14 17:55:08 +02001078>
1079 let r_indent_ess_compatible = 1
1080<
1081Below is an example of indentation with and without this option enabled:
1082>
1083 ### r_indent_ess_compatible = 1 ### r_indent_ess_compatible = 0
1084 foo <- foo <-
1085 function(x) function(x)
1086 { {
1087 paste(x) paste(x)
1088 } }
1089<
Bram Moolenaarfc65cab2018-08-28 22:58:02 +02001090The code will be indented after lines that match the pattern
1091`'\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$'`. If you want indentation after
1092lines that match a different pattern, you should set the appropriate value of
1093`r_indent_op_pattern` in your |vimrc|.
1094
Bram Moolenaar5302d9e2011-09-14 17:55:08 +02001095
Bram Moolenaar7263a772007-05-10 17:35:54 +00001096SHELL *ft-sh-indent*
1097
1098The amount of indent applied under various circumstances in a shell file can
1099be configured by setting the following keys in the |Dictionary|
1100b:sh_indent_defaults to a specific amount or to a |Funcref| that references a
1101function that will return the amount desired:
1102
1103b:sh_indent_options['default'] Default amount of indent.
1104
1105b:sh_indent_options['continuation-line']
1106 Amount of indent to add to a continued line.
1107
1108b:sh_indent_options['case-labels']
1109 Amount of indent to add for case labels.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001110 (not actually implemented)
Bram Moolenaar7263a772007-05-10 17:35:54 +00001111
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001112b:sh_indent_options['case-statements']
Bram Moolenaar7263a772007-05-10 17:35:54 +00001113 Amount of indent to add for case statements.
1114
1115b:sh_indent_options['case-breaks']
1116 Amount of indent to add (or more likely
1117 remove) for case breaks.
1118
Bram Moolenaarda2303d2005-08-30 21:55:26 +00001119VERILOG *ft-verilog-indent*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120
1121General block statements such as if, for, case, always, initial, function,
1122specify and begin, etc., are indented. The module block statements (first
1123level blocks) are not indented by default. you can turn on the indent with
1124setting a variable in the .vimrc as follows: >
1125
1126 let b:verilog_indent_modules = 1
1127
1128then the module blocks will be indented. To stop this, remove the variable: >
1129
1130 :unlet b:verilog_indent_modules
1131
1132To set the variable only for Verilog file. The following statements can be
1133used: >
1134
1135 au BufReadPost * if exists("b:current_syntax")
1136 au BufReadPost * if b:current_syntax == "verilog"
1137 au BufReadPost * let b:verilog_indent_modules = 1
1138 au BufReadPost * endif
1139 au BufReadPost * endif
1140
1141Furthermore, setting the variable b:verilog_indent_width to change the
1142indenting width (default is 'shiftwidth'): >
1143
1144 let b:verilog_indent_width = 4
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01001145 let b:verilog_indent_width = shiftwidth() * 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146
1147In addition, you can turn the verbose mode for debug issue: >
1148
1149 let b:verilog_indent_verbose = 1
1150
1151Make sure to do ":set cmdheight=2" first to allow the display of the message.
1152
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001153
Bram Moolenaar3577c6f2008-06-24 21:16:56 +00001154VHDL *ft-vhdl-indent*
1155
1156Alignment of generic/port mapping statements are performed by default. This
1157causes the following alignment example: >
1158
1159 ENTITY sync IS
1160 PORT (
1161 clk : IN STD_LOGIC;
1162 reset_n : IN STD_LOGIC;
1163 data_input : IN STD_LOGIC;
1164 data_out : OUT STD_LOGIC
1165 );
1166 END ENTITY sync;
1167
1168To turn this off, add >
1169
1170 let g:vhdl_indent_genportmap = 0
1171
1172to the .vimrc file, which causes the previous alignment example to change: >
1173
1174 ENTITY sync IS
1175 PORT (
1176 clk : IN STD_LOGIC;
1177 reset_n : IN STD_LOGIC;
1178 data_input : IN STD_LOGIC;
1179 data_out : OUT STD_LOGIC
1180 );
1181 END ENTITY sync;
1182
1183----------------------------------------
1184
1185Alignment of right-hand side assignment "<=" statements are performed by
1186default. This causes the following alignment example: >
1187
1188 sig_out <= (bus_a(1) AND
1189 (sig_b OR sig_c)) OR
1190 (bus_a(0) AND sig_d);
1191
1192To turn this off, add >
1193
1194 let g:vhdl_indent_rhsassign = 0
1195
1196to the .vimrc file, which causes the previous alignment example to change: >
1197
1198 sig_out <= (bus_a(1) AND
1199 (sig_b OR sig_c)) OR
1200 (bus_a(0) AND sig_d);
1201
1202----------------------------------------
1203
1204Full-line comments (lines that begin with "--") are indented to be aligned with
1205the very previous line's comment, PROVIDED that a whitespace follows after
1206"--".
1207
1208For example: >
1209
1210 sig_a <= sig_b; -- start of a comment
1211 -- continuation of the comment
1212 -- more of the same comment
1213
1214While in Insert mode, after typing "-- " (note the space " "), hitting CTRL-F
1215will align the current "-- " with the previous line's "--".
1216
1217If the very previous line does not contain "--", THEN the full-line comment
1218will be aligned with the start of the next non-blank line that is NOT a
1219full-line comment.
1220
1221Indenting the following code: >
1222
1223 sig_c <= sig_d; -- comment 0
1224 -- comment 1
1225 -- comment 2
1226 --debug_code:
1227 --PROCESS(debug_in)
1228 --BEGIN
1229 -- FOR i IN 15 DOWNTO 0 LOOP
1230 -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i);
1231 -- END LOOP;
1232 --END PROCESS debug_code;
1233
1234 -- comment 3
1235 sig_e <= sig_f; -- comment 4
1236 -- comment 5
1237
1238results in: >
1239
1240 sig_c <= sig_d; -- comment 0
1241 -- comment 1
1242 -- comment 2
1243 --debug_code:
1244 --PROCESS(debug_in)
1245 --BEGIN
1246 -- FOR i IN 15 DOWNTO 0 LOOP
1247 -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i);
1248 -- END LOOP;
1249 --END PROCESS debug_code;
1250
1251 -- comment 3
1252 sig_e <= sig_f; -- comment 4
1253 -- comment 5
1254
1255Notice that "--debug_code:" does not align with "-- comment 2"
1256because there is no whitespace that follows after "--" in "--debug_code:".
1257
1258Given the dynamic nature of indenting comments, indenting should be done TWICE.
1259On the first pass, code will be indented. On the second pass, full-line
1260comments will be indented according to the correctly indented code.
1261
1262
Bram Moolenaarda2303d2005-08-30 21:55:26 +00001263VIM *ft-vim-indent*
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +01001264 *g:vim_indent*
1265Vim scripts indentation can be configured with the `g:vim_indent` dictionary
1266variable. It supports 3 keys, `line_continuation`, `more_in_bracket_block`,
1267and `searchpair_timeout`.
1268`line_continuation` expects a number which will be added to the indent level of
1269a continuation line starting with a backslash, and defaults to
h_east59858792023-10-25 22:47:05 +09001270`shiftwidth() * 3` . It also accepts a string, which is evaluated at runtime.
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +01001271`more_in_bracket_block` expects a boolean value; when on, an extra
1272`shiftwidth()` is added inside blocks surrounded with brackets. It defaults to
1273`v:false`.
1274`searchpair_timeout` expects a number which will be passed to `searchpair()` as
1275a timeout. Increasing the value might give more accurate results, but also
1276causes the indentation to take more time. It defaults to 100 (milliseconds).
1277
h_east59858792023-10-25 22:47:05 +09001278Example of configuration: >
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +01001279
1280 let g:vim_indent = #{
1281 \ line_continuation: shiftwidth() * 3,
1282 \ more_in_bracket_block: v:false,
1283 \ searchpair_timeout: 100,
1284 \ }
h_east59858792023-10-25 22:47:05 +09001285<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00001286 *g:vim_indent_cont*
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +01001287This variable is equivalent to `g:vim_indent.line_continuation`.
1288It's supported for backward compatibility.
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001289
Christian Brabandtb4eb3f12024-02-29 17:23:51 +01001290YAML *ft-yaml-indent*
1291
Christian Brabandt8fad5d52024-02-29 18:12:30 +01001292By default, the yaml indent script does not try to detect multiline scalars.
Christian Brabandtb4eb3f12024-02-29 17:23:51 +01001293If you want to enable this, set the following variable: >
1294
1295 let g:yaml_indent_multiline_scalar = 1
h-east53753f62024-05-05 18:42:31 +02001296<
Bram Moolenaar91f84f62018-07-29 15:07:52 +02001297 vim:tw=78:ts=8:noet:ft=help:norl: