blob: 87d5c0bd5e3cbea1851afa99120aba2f9e7966e6 [file] [log] [blame]
Bram Moolenaar98056532019-12-12 14:18:35 +01001*indent.txt* For Vim version 8.2. Last change: 2019 Dec 07
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
25Note that this will not work when the |+smartindent| or |+cindent| features
26have been disabled at compile time.
27
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000028There are in fact four main methods available for indentation, each one
29overrides the previous if it is enabled, or non-empty for 'indentexpr':
Bram Moolenaar071d4272004-06-13 20:20:40 +000030'autoindent' uses the indent from the previous line.
31'smartindent' is like 'autoindent' but also recognizes some C syntax to
32 increase/reduce the indent where appropriate.
33'cindent' Works more cleverly than the other two and is configurable to
34 different indenting styles.
35'indentexpr' The most flexible of all: Evaluates an expression to compute
36 the indent of a line. When non-empty this method overrides
37 the other ones. See |indent-expression|.
38The rest of this section describes the 'cindent' option.
39
40Note that 'cindent' indenting does not work for every code scenario. Vim
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +000041is not a C compiler: it does not recognize all syntax. One requirement is
42that toplevel functions have a '{' in the first column. Otherwise they are
43easily confused with declarations.
Bram Moolenaar071d4272004-06-13 20:20:40 +000044
45These four options control C program indenting:
46'cindent' Enables Vim to perform C program indenting automatically.
47'cinkeys' Specifies which keys trigger reindenting in insert mode.
48'cinoptions' Sets your preferred indent style.
49'cinwords' Defines keywords that start an extra indent in the next line.
50
51If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
52Vim's built-in algorithm rather than calling an external program.
53
54See |autocommand| for how to set the 'cindent' option automatically for C code
55files and reset it for others.
56
57 *cinkeys-format* *indentkeys-format*
58The 'cinkeys' option is a string that controls Vim's indenting in response to
59typing certain characters or commands in certain contexts. Note that this not
60only triggers C-indenting. When 'indentexpr' is not empty 'indentkeys' is
61used instead. The format of 'cinkeys' and 'indentkeys' is equal.
62
Bram Moolenaarce655742019-01-31 14:12:57 +010063The default is "0{,0},0),0],:,0#,!^F,o,O,e" which specifies that indenting
64occurs as follows:
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
66 "0{" if you type '{' as the first character in a line
67 "0}" if you type '}' as the first character in a line
68 "0)" if you type ')' as the first character in a line
Bram Moolenaarce655742019-01-31 14:12:57 +010069 "0]" if you type ']' as the first character in a line
Bram Moolenaar071d4272004-06-13 20:20:40 +000070 ":" if you type ':' after a label or case statement
71 "0#" if you type '#' as the first character in a line
72 "!^F" if you type CTRL-F (which is not inserted)
73 "o" if you type a <CR> anywhere or use the "o" command (not in
74 insert mode!)
75 "O" if you use the "O" command (not in insert mode!)
76 "e" if you type the second 'e' for an "else" at the start of a
77 line
78
Bram Moolenaare2f98b92006-03-29 21:18:24 +000079Characters that can precede each key: *i_CTRL-F*
Bram Moolenaar071d4272004-06-13 20:20:40 +000080! When a '!' precedes the key, Vim will not insert the key but will
81 instead reindent the current line. This allows you to define a
82 command key for reindenting the current line. CTRL-F is the default
83 key for this. Be careful if you define CTRL-I for this because CTRL-I
84 is the ASCII code for <Tab>.
85* When a '*' precedes the key, Vim will reindent the line before
86 inserting the key. If 'cinkeys' contains "*<Return>", Vim reindents
87 the current line before opening a new line.
880 When a zero precedes the key (but appears after '!' or '*') Vim will
89 reindent the line only if the key is the first character you type in
90 the line. When used before "=" Vim will only reindent the line if
91 there is only white space before the word.
92
93When neither '!' nor '*' precedes the key, Vim reindents the line after you
94type the key. So ';' sets the indentation of a line which includes the ';'.
95
96Special key names:
97<> Angle brackets mean spelled-out names of keys. For example: "<Up>",
98 "<Ins>" (see |key-notation|).
99^ Letters preceded by a caret (^) are control characters. For example:
100 "^F" is CTRL-F.
101o Reindent a line when you use the "o" command or when Vim opens a new
102 line below the current one (e.g., when you type <Enter> in insert
103 mode).
104O Reindent a line when you use the "O" command.
105e Reindent a line that starts with "else" when you type the second 'e'.
106: Reindent a line when a ':' is typed which is after a label or case
107 statement. Don't reindent for a ":" in "class::method" for C++. To
108 Reindent for any ":", use "<:>".
109=word Reindent when typing the last character of "word". "word" may
110 actually be part of another word. Thus "=end" would cause reindenting
111 when typing the "d" in "endif" or "endwhile". But not when typing
112 "bend". Also reindent when completion produces a word that starts
113 with "word". "0=word" reindents when there is only white space before
114 the word.
115=~word Like =word, but ignore case.
116
117If you really want to reindent when you type 'o', 'O', 'e', '0', '<', '>',
118'*', ':' or '!', use "<o>", "<O>", "<e>", "<0>", "<<>", "<>>", "<*>", "<:>" or
119"<!>", respectively, for those keys.
120
121For an emacs-style indent mode where lines aren't indented every time you
Bram Moolenaar5c3e56a2007-05-12 13:43:14 +0000122press <Enter> but only if you press <Tab>, I suggest:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123 :set cinkeys=0{,0},:,0#,!<Tab>,!^F
124You might also want to switch off 'autoindent' then.
125
126Note: If you change the current line's indentation manually, Vim ignores the
127cindent settings for that line. This prevents vim from reindenting after you
128have changed the indent by typing <BS>, <Tab>, or <Space> in the indent or
129used CTRL-T or CTRL-D.
130
131 *cinoptions-values*
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200132The 'cinoptions' option sets how Vim performs indentation. The value after
133the option character can be one of these (N is any number):
134 N indent N spaces
135 -N indent N spaces to the left
Bram Moolenaar5302d9e2011-09-14 17:55:08 +0200136 Ns N times 'shiftwidth' spaces
137 -Ns N times 'shiftwidth' spaces to the left
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200138
139In the list below,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140"N" represents a number of your choice (the number can be negative). When
141there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
142"1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc. You can use a
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200143decimal point, too: "-0.5s" is minus half a 'shiftwidth'.
144The examples below assume a 'shiftwidth' of 4.
145 *cino->*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146 >N Amount added for "normal" indent. Used after a line that should
147 increase the indent (lines starting with "if", an opening brace,
148 etc.). (default 'shiftwidth').
149
150 cino= cino=>2 cino=>2s >
151 if (cond) if (cond) if (cond)
152 { { {
153 foo; foo; foo;
154 } } }
155<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200156 *cino-e*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157 eN Add N to the prevailing indent inside a set of braces if the
158 opening brace at the End of the line (more precise: is not the
159 first character in a line). This is useful if you want a
160 different indent when the '{' is at the start of the line from
161 when '{' is at the end of the line. (default 0).
162
163 cino= cino=e2 cino=e-2 >
164 if (cond) { if (cond) { if (cond) {
165 foo; foo; foo;
166 } } }
167 else else else
168 { { {
169 bar; bar; bar;
170 } } }
171<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200172 *cino-n*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000173 nN Add N to the prevailing indent for a statement after an "if",
174 "while", etc., if it is NOT inside a set of braces. This is
175 useful if you want a different indent when there is no '{'
176 before the statement from when there is a '{' before it.
177 (default 0).
178
179 cino= cino=n2 cino=n-2 >
180 if (cond) if (cond) if (cond)
181 foo; foo; foo;
182 else else else
183 { { {
184 bar; bar; bar;
185 } } }
186<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200187 *cino-f*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188 fN Place the first opening brace of a function or other block in
189 column N. This applies only for an opening brace that is not
190 inside other braces and is at the start of the line. What comes
191 after the brace is put relative to this brace. (default 0).
192
193 cino= cino=f.5s cino=f1s >
194 func() func() func()
195 { { {
196 int foo; int foo; int foo;
197<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200198 *cino-{*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199 {N Place opening braces N characters from the prevailing indent.
200 This applies only for opening braces that are inside other
201 braces. (default 0).
202
203 cino= cino={.5s cino={1s >
204 if (cond) if (cond) if (cond)
205 { { {
206 foo; foo; foo;
207<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200208 *cino-}*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209 }N Place closing braces N characters from the matching opening
210 brace. (default 0).
211
212 cino= cino={2,}-0.5s cino=}2 >
213 if (cond) if (cond) if (cond)
214 { { {
215 foo; foo; foo;
216 } } }
217<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200218 *cino-^*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219 ^N Add N to the prevailing indent inside a set of braces if the
220 opening brace is in column 0. This can specify a different
221 indent for whole of a function (some may like to set it to a
222 negative number). (default 0).
223
224 cino= cino=^-2 cino=^-s >
225 func() func() func()
226 { { {
227 if (cond) if (cond) if (cond)
228 { { {
229 a = b; a = b; a = b;
230 } } }
231 } } }
232<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200233 *cino-L*
Bram Moolenaar02c707a2010-07-17 17:12:06 +0200234 LN Controls placement of jump labels. If N is negative, the label
235 will be placed at column 1. If N is non-negative, the indent of
236 the label will be the prevailing indent minus N. (default -1).
237
238 cino= cino=L2 cino=Ls >
239 func() func() func()
240 { { {
241 { { {
242 stmt; stmt; stmt;
243 LABEL: LABEL: LABEL:
244 } } }
245 } } }
246<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200247 *cino-:*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248 :N Place case labels N characters from the indent of the switch().
249 (default 'shiftwidth').
250
251 cino= cino=:0 >
252 switch (x) switch(x)
253 { {
254 case 1: case 1:
255 a = b; a = b;
256 default: default:
257 } }
258<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200259 *cino-=*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260 =N Place statements occurring after a case label N characters from
261 the indent of the label. (default 'shiftwidth').
262
263 cino= cino==10 >
264 case 11: case 11: a = a + 1;
265 a = a + 1; b = b + 1;
266<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200267 *cino-l*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268 lN If N != 0 Vim will align with a case label instead of the
269 statement after it in the same line.
270
271 cino= cino=l1 >
272 switch (a) { switch (a) {
273 case 1: { case 1: {
274 break; break;
275 } }
276<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200277 *cino-b*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278 bN If N != 0 Vim will align a final "break" with the case label,
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000279 so that case..break looks like a sort of block. (default: 0).
Bram Moolenaar81af9252010-12-10 20:35:50 +0100280 When using 1, consider adding "0=break" to 'cinkeys'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281
282 cino= cino=b1 >
283 switch (x) switch(x)
284 { {
285 case 1: case 1:
286 a = b; a = b;
287 break; break;
288
289 default: default:
290 a = 0; a = 0;
291 break; break;
292 } }
293<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200294 *cino-g*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295 gN Place C++ scope declarations N characters from the indent of the
296 block they are in. (default 'shiftwidth'). A scope declaration
297 can be "public:", "protected:" or "private:".
298
299 cino= cino=g0 >
300 { {
301 public: public:
302 a = b; a = b;
303 private: private:
304 } }
305<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200306 *cino-h*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307 hN Place statements occurring after a C++ scope declaration N
308 characters from the indent of the label. (default
309 'shiftwidth').
310
311 cino= cino=h10 >
312 public: public: a = a + 1;
313 a = a + 1; b = b + 1;
314<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200315 *cino-N*
316 NN Indent inside C++ namespace N characters extra compared to a
317 normal block. (default 0).
318
319 cino= cino=N-s >
320 namespace { namespace {
321 void function(); void function();
322 } }
323
324 namespace my namespace my
325 { {
326 void function(); void function();
327 } }
328<
Bram Moolenaar7720ba82017-03-08 22:19:26 +0100329 *cino-E*
330 EN Indent inside C++ linkage specifications (extern "C" or
331 extern "C++") N characters extra compared to a normal block.
332 (default 0).
333
334 cino= cino=E-s >
335 extern "C" { extern "C" {
336 void function(); void function();
337 } }
338
339 extern "C" extern "C"
340 { {
341 void function(); void function();
342 } }
343<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200344 *cino-p*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345 pN Parameter declarations for K&R-style function declarations will
346 be indented N characters from the margin. (default
347 'shiftwidth').
348
349 cino= cino=p0 cino=p2s >
350 func(a, b) func(a, b) func(a, b)
351 int a; int a; int a;
352 char b; char b; char b;
353<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200354 *cino-t*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355 tN Indent a function return type declaration N characters from the
356 margin. (default 'shiftwidth').
357
358 cino= cino=t0 cino=t7 >
359 int int int
360 func() func() func()
361<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200362 *cino-i*
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000363 iN Indent C++ base class declarations and constructor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364 initializations, if they start in a new line (otherwise they
365 are aligned at the right side of the ':').
366 (default 'shiftwidth').
367
368 cino= cino=i0 >
369 class MyClass : class MyClass :
370 public BaseClass public BaseClass
371 {} {}
372 MyClass::MyClass() : MyClass::MyClass() :
373 BaseClass(3) BaseClass(3)
374 {} {}
375<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200376 *cino-+*
Bram Moolenaar662db672011-03-22 14:05:35 +0100377 +N Indent a continuation line (a line that spills onto the next)
378 inside a function N additional characters. (default
379 'shiftwidth').
380 Outside of a function, when the previous line ended in a
381 backslash, the 2 * N is used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382
383 cino= cino=+10 >
384 a = b + 9 * a = b + 9 *
385 c; c;
386<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200387 *cino-c*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388 cN Indent comment lines after the comment opener, when there is no
389 other text with which to align, N characters from the comment
390 opener. (default 3). See also |format-comments|.
391
392 cino= cino=c5 >
393 /* /*
394 text. text.
395 */ */
396<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200397 *cino-C*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 CN When N is non-zero, indent comment lines by the amount specified
399 with the c flag above even if there is other text behind the
400 comment opener. (default 0).
401
402 cino=c0 cino=c0,C1 >
403 /******** /********
404 text. text.
405 ********/ ********/
406< (Example uses ":set comments& comments-=s1:/* comments^=s0:/*")
407
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200408 *cino-/*
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000409 /N Indent comment lines N characters extra. (default 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410 cino= cino=/4 >
411 a = b; a = b;
412 /* comment */ /* comment */
413 c = d; c = d;
414<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200415 *cino-(*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416 (N When in unclosed parentheses, indent N characters from the line
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200417 with the unclosed parenthesis. Add a 'shiftwidth' for every
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +0200418 extra unclosed parentheses. When N is 0 or the unclosed
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200419 parenthesis is the first non-white character in its line, line
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +0200420 up with the next non-white character after the unclosed
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200421 parenthesis. (default 'shiftwidth' * 2).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422
423 cino= cino=(0 >
424 if (c1 && (c2 || if (c1 && (c2 ||
425 c3)) c3))
426 foo; foo;
427 if (c1 && if (c1 &&
428 (c2 || c3)) (c2 || c3))
429 { {
430<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200431 *cino-u*
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +0200432 uN Same as (N, but for one nesting level deeper.
433 (default 'shiftwidth').
Bram Moolenaar071d4272004-06-13 20:20:40 +0000434
435 cino= cino=u2 >
436 if (c123456789 if (c123456789
437 && (c22345 && (c22345
438 || c3)) || c3))
439<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200440 *cino-U*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441 UN When N is non-zero, do not ignore the indenting specified by
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200442 ( or u in case that the unclosed parenthesis is the first
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443 non-white character in its line. (default 0).
444
445 cino= or cino=(s cino=(s,U1 >
446 c = c1 && c = c1 &&
447 ( (
448 c2 || c2 ||
449 c3 c3
450 ) && c4; ) && c4;
451<
Bram Moolenaar5302d9e2011-09-14 17:55:08 +0200452 *cino-w*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453 wN When in unclosed parentheses and N is non-zero and either
454 using "(0" or "u0", respectively, or using "U0" and the unclosed
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200455 parenthesis is the first non-white character in its line, line
456 up with the character immediately after the unclosed parenthesis
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457 rather than the first non-white character. (default 0).
458
459 cino=(0 cino=(0,w1 >
460 if ( c1 if ( c1
461 && ( c2 && ( c2
462 || c3)) || c3))
463 foo; foo;
464<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200465 *cino-W*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000466 WN When in unclosed parentheses and N is non-zero and either
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200467 using "(0" or "u0", respectively and the unclosed parenthesis is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468 the last non-white character in its line and it is not the
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200469 closing parenthesis, indent the following line N characters
Bram Moolenaar071d4272004-06-13 20:20:40 +0000470 relative to the outer context (i.e. start of the line or the
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200471 next unclosed parenthesis). (default: 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472
473 cino=(0 cino=(0,W4 >
474 a_long_line( a_long_line(
475 argument, argument,
476 argument); argument);
477 a_short_line(argument, a_short_line(argument,
478 argument); argument);
479<
Bram Moolenaar3675fa02012-04-05 17:17:42 +0200480 *cino-k*
481 kN When in unclosed parentheses which follow "if", "for" or
482 "while" and N is non-zero, overrides the behaviour defined by
483 "(N": causes the indent to be N characters relative to the outer
484 context (i.e. the line where "if", "for" or "while" is). Has
485 no effect on deeper levels of nesting. Affects flags like "wN"
486 only for the "if", "for" and "while" conditions. If 0, defaults
487 to behaviour defined by the "(N" flag. (default: 0).
488
489 cino=(0 cino=(0,ks >
490 if (condition1 if (condition1
491 && condition2) && condition2)
492 action(); action();
493 function(argument1 function(argument1
494 && argument2); && argument2);
495<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200496 *cino-m*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 mN When N is non-zero, line up a line starting with a closing
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200498 parenthesis with the first character of the line with the
499 matching opening parenthesis. (default 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500
501 cino=(s cino=(s,m1 >
502 c = c1 && ( c = c1 && (
503 c2 || c2 ||
504 c3 c3
505 ) && c4; ) && c4;
506 if ( if (
507 c1 && c2 c1 && c2
508 ) )
509 foo; foo;
510<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200511 *cino-M*
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000512 MN When N is non-zero, line up a line starting with a closing
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200513 parenthesis with the first character of the previous line.
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000514 (default 0).
515
516 cino= cino=M1 >
517 if (cond1 && if (cond1 &&
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000518 cond2 cond2
519 ) )
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000520<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200521 *java-cinoptions* *java-indenting* *cino-j*
Bram Moolenaar97293012011-07-18 19:40:27 +0200522 jN Indent Java anonymous classes correctly. Also works well for
523 Javascript. The value 'N' is currently unused but must be
524 non-zero (e.g. 'j1'). 'j1' will indent for example the
525 following code snippet correctly: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526
527 object.add(new ChangeListener() {
528 public void stateChanged(ChangeEvent e) {
529 do_something();
530 }
531 });
532<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200533 *javascript-cinoptions* *javascript-indenting* *cino-J*
Bram Moolenaar3acfc302010-07-11 17:23:02 +0200534 JN Indent JavaScript object declarations correctly by not confusing
Bram Moolenaar664f3cf2019-12-07 16:03:51 +0100535 them with labels. The value 'N' is currently unused but must be
Bram Moolenaar97293012011-07-18 19:40:27 +0200536 non-zero (e.g. 'J1'). If you enable this you probably also want
537 to set |cino-j|. >
Bram Moolenaar3acfc302010-07-11 17:23:02 +0200538
539 var bar = {
540 foo: {
541 that: this,
542 some: ok,
543 },
Bram Moolenaar664f3cf2019-12-07 16:03:51 +0100544 "bar":{
Bram Moolenaar3acfc302010-07-11 17:23:02 +0200545 a : 2,
546 b: "123abc",
547 x: 4,
548 "y": 5
549 }
550 }
551<
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200552 *cino-)*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 )N Vim searches for unclosed parentheses at most N lines away.
554 This limits the time needed to search for parentheses. (default
555 20 lines).
556
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200557 *cino-star*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 *N Vim searches for unclosed comments at most N lines away. This
559 limits the time needed to search for the start of a comment.
Bram Moolenaard09acef2012-09-21 14:54:30 +0200560 If your /* */ comments stop indenting after N lines this is the
Bram Moolenaar8e5af3e2011-04-28 19:02:44 +0200561 value you will want to change.
Bram Moolenaar6dfc28b2010-02-11 14:19:15 +0100562 (default 70 lines).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200564 *cino-#*
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +0100565 #N When N is non-zero recognize shell/Perl comments starting with
566 '#', do not recognize preprocessor lines; allow right-shifting
567 lines that start with "#".
568 When N is zero (default): don't recognize '#' comments, do
569 recognize preprocessor lines; right-shifting lines that start
570 with "#" does not work.
Bram Moolenaar39353fd2007-03-27 09:02:11 +0000571
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200572 *cino-P*
Bram Moolenaard881b512020-05-31 17:49:30 +0200573 PN When N is non-zero recognize C pragmas, and indent them like any
574 other code; does not concern other preprocessor directives.
575 When N is zero (default): don't recognize C pragmas, treating
576 them like every other preprocessor directive.
577
578
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579The defaults, spelled out in full, are:
Bram Moolenaar7720ba82017-03-08 22:19:26 +0100580 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 +0200581 c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0,P0
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582
583Vim puts a line in column 1 if:
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +0100584- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585- It starts with a label (a keyword followed by ':', other than "case" and
Bram Moolenaar02c707a2010-07-17 17:12:06 +0200586 "default") and 'cinoptions' does not contain an 'L' entry with a positive
587 value.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588- Any combination of indentations causes the line to have less than 0
589 indentation.
590
591==============================================================================
5922. Indenting by expression *indent-expression*
593
594The basics for using flexible indenting are explained in section |30.3| of the
595user manual.
596
597If you want to write your own indent file, it must set the 'indentexpr'
Bram Moolenaarba3ff532018-11-04 14:45:49 +0100598option. Setting the 'indentkeys' option is often useful.
599See the $VIMRUNTIME/indent/README.txt file for hints.
600See the $VIMRUNTIME/indent directory for examples.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601
602
603REMARKS ABOUT SPECIFIC INDENT FILES ~
604
605
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100606CLOJURE *ft-clojure-indent* *clojure-indent*
607
608Clojure indentation differs somewhat from traditional Lisps, due in part to
609the use of square and curly brackets, and otherwise by community convention.
Bram Moolenaarbaca7f72013-09-22 14:42:24 +0200610These conventions are not universally followed, so the Clojure indent script
611offers a few configurable options, listed below.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100612
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +0100613If the current vim does not include |searchpairpos()|, the indent script falls
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100614back to normal 'lisp' indenting, and the following options are ignored.
615
616 *g:clojure_maxlines*
617
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +0100618Set maximum scan distance of |searchpairpos()|. Larger values trade
619performance for correctness when dealing with very long forms. A value of 0
620will scan without limits.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100621>
622 " Default
623 let g:clojure_maxlines = 100
624<
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100625 *g:clojure_fuzzy_indent*
626 *g:clojure_fuzzy_indent_patterns*
627 *g:clojure_fuzzy_indent_blacklist*
628
629The 'lispwords' option is a list of comma-separated words that mark special
630forms whose subforms must be indented with two spaces.
631
632For example:
633>
634 (defn bad []
635 "Incorrect indentation")
636
637 (defn good []
638 "Correct indentation")
639<
640If you would like to specify 'lispwords' with a |pattern| instead, you can use
641the fuzzy indent feature:
642>
643 " Default
644 let g:clojure_fuzzy_indent = 1
645 let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let']
646 let g:clojure_fuzzy_indent_blacklist =
647 \ ['-fn$', '\v^with-%(meta|out-str|loading-context)$']
648
649 " Legacy comma-delimited string version; the list format above is
650 " recommended. Note that patterns are implicitly anchored with ^ and $
651 let g:clojure_fuzzy_indent_patterns = 'with.*,def.*,let.*'
652<
653|g:clojure_fuzzy_indent_patterns| and |g:clojure_fuzzy_indent_blacklist| are
654|Lists| of patterns that will be matched against the unquoted, unqualified
655symbol at the head of a list. This means that a pattern like "^foo" will match
656all these candidates: "foobar", "my.ns/foobar", and "#'foobar".
657
658Each candidate word is tested for special treatment in this order:
659
660 1. Return true if word is literally in 'lispwords'
661 2. Return false if word matches a pattern in
662 |g:clojure_fuzzy_indent_blacklist|
663 3. Return true if word matches a pattern in
664 |g:clojure_fuzzy_indent_patterns|
665 4. Return false and indent normally otherwise
666
667 *g:clojure_special_indent_words*
668
669Some forms in Clojure are indented so that every subform is indented only two
670spaces, regardless of 'lispwords'. If you have a custom construct that should
671be indented in this idiosyncratic fashion, you can add your symbols to the
672default list below.
673>
674 " Default
675 let g:clojure_special_indent_words =
676 \ 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
677<
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100678 *g:clojure_align_multiline_strings*
679
680Align subsequent lines in multiline strings to the column after the opening
681quote, instead of the same column.
682
683For example:
684>
685 (def default
686 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
687 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
688 enim ad minim veniam, quis nostrud exercitation ullamco laboris
689 nisi ut aliquip ex ea commodo consequat.")
690
691 (def aligned
692 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
693 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
694 enim ad minim veniam, quis nostrud exercitation ullamco laboris
695 nisi ut aliquip ex ea commodo consequat.")
696<
697This option is off by default.
698>
699 " Default
700 let g:clojure_align_multiline_strings = 0
701<
Bram Moolenaar438f67a2014-01-07 06:09:28 +0100702 *g:clojure_align_subforms*
703
704By default, parenthesized compound forms that look like function calls and
705whose head subform is on its own line have subsequent subforms indented by
706two spaces relative to the opening paren:
707>
708 (foo
709 bar
710 baz)
711<
712Setting this option changes this behavior so that all subforms are aligned to
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100713the same column, emulating the default behavior of clojure-mode.el:
Bram Moolenaar438f67a2014-01-07 06:09:28 +0100714>
715 (foo
716 bar
717 baz)
718<
719This option is off by default.
720>
721 " Default
722 let g:clojure_align_subforms = 0
723<
Bram Moolenaarfa13eef2013-02-06 17:34:04 +0100724
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000725FORTRAN *ft-fortran-indent*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726
Bram Moolenaar251e1912011-06-19 05:09:16 +0200727Block if, select case, where, and forall constructs are indented. So are
728type, interface, associate, block, and enum constructs. The indenting of
729subroutines, functions, modules, and program blocks is optional. Comments,
730labelled statements and continuation lines are indented if the Fortran is in
731free source form, whereas they are not indented if the Fortran is in fixed
732source form because of the left margin requirements. Hence manual indent
733corrections will be necessary for labelled statements and continuation lines
734when fixed source form is being used. For further discussion of the method
735used for the detection of source format see |ft-fortran-syntax|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736
737Do loops ~
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000738All do loops are left unindented by default. Do loops can be unstructured in
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739Fortran with (possibly multiple) loops ending on a labelled executable
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000740statement of almost arbitrary type. Correct indentation requires
741compiler-quality parsing. Old code with do loops ending on labelled statements
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742of arbitrary type can be indented with elaborate programs such as Tidy
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000743(http://www.unb.ca/chem/ajit/f_tidy.htm). Structured do/continue loops are
Bram Moolenaar071d4272004-06-13 20:20:40 +0000744also left unindented because continue statements are also used for purposes
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000745other than ending a do loop. Programs such as Tidy can convert structured
746do/continue loops to the do/enddo form. Do loops of the do/enddo variety can
747be indented. If you use only structured loops of the do/enddo form, you should
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748declare this by setting the fortran_do_enddo variable in your .vimrc as
749follows >
750
751 let fortran_do_enddo=1
752
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000753in which case do loops will be indented. If all your loops are of do/enddo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754type only in, say, .f90 files, then you should set a buffer flag with an
755autocommand such as >
756
757 au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1
758
759to get do loops indented in .f90 files and left alone in Fortran files with
760other extensions such as .for.
761
Bram Moolenaar251e1912011-06-19 05:09:16 +0200762Program units ~
763The indenting of program units (subroutines, functions, modules, and program
764blocks) is enabled by default but can be suppressed if a lighter, screen-width
765preserving indent style is desired. To suppress the indenting of program
766units for all fortran files set the global fortran_indent_less variable in
767your .vimrc as follows >
768
769 let fortran_indent_less=1
770
771A finer level of suppression can be achieved by setting the corresponding
772buffer-local variable as follows >
773
774 let b:fortran_indent_less=1
775
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200777HTML *ft-html-indent* *html-indent* *html-indenting*
778
779This is about variables you can set in your vimrc to customize HTML indenting.
780
781You can set the indent for the first line after <script> and <style>
782"blocktags" (default "zero"): >
783
784 :let g:html_indent_script1 = "inc"
785 :let g:html_indent_style1 = "inc"
786<
787 VALUE MEANING ~
788 "zero" zero indent
789 "auto" auto indent (same indent as the blocktag)
790 "inc" auto indent + one indent step
791
792Many tags increase the indent for what follows per default (see "Add Indent
Bram Moolenaar52b91d82013-06-15 21:39:51 +0200793Tags" in the script). You can add further tags with: >
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200794
795 :let g:html_indent_inctags = "html,body,head,tbody"
796
797You can also remove such tags with: >
798
799 :let g:html_indent_autotags = "th,td,tr,tfoot,thead"
800
801Default value is empty for both variables. Note: the initial "inctags" are
802only defined once per Vim session.
803
804User variables are only read when the script is sourced. To enable your
Bram Moolenaar52b91d82013-06-15 21:39:51 +0200805changes during a session, without reloading the HTML file, you can manually
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200806do: >
807
808 :call HtmlIndent_CheckUserSettings()
809
810Detail:
811 Calculation of indent inside "blocktags" with "alien" content:
812 BLOCKTAG INDENT EXPR WHEN APPLICABLE ~
Bram Moolenaar52b91d82013-06-15 21:39:51 +0200813 <script> : {customizable} if first line of block
814 : cindent(v:lnum) if attributes empty or contain "java"
815 : -1 else (vbscript, tcl, ...)
816 <style> : {customizable} if first line of block
817 : GetCSSIndent() else
Bram Moolenaarec7944a2013-06-12 21:29:15 +0200818 <!-- --> : -1
819
820
Bram Moolenaar32b364f2019-12-08 15:07:48 +0100821MATLAB *ft-matlab-indent* *matlab-indent* *matlab-indenting*
822
823The setting Function indenting format in MATLAB Editor/Debugger Language
824Preferences corresponds to: >
825 :let g:MATLAB_function_indent = {0, 1 or 2 (default)}
826
827Where 0 is for Classic, 1 for Indent nested functions and 2 for Indent all
828functions.
829
830
Bram Moolenaarc236c162008-07-13 17:41:49 +0000831PHP *ft-php-indent* *php-indent* *php-indenting*
832
833NOTE: PHP files will be indented correctly only if PHP |syntax| is active.
834
835If you are editing a file in Unix 'fileformat' and '\r' characters are present
836before new lines, indentation won't proceed correctly ; you have to remove
837those useless characters first with a command like: >
838
839 :%s /\r$//g
840
841Or, you can simply |:let| the variable PHP_removeCRwhenUnix to 1 and the
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200842script will silently remove them when Vim loads a PHP file (at each |BufRead|).
Bram Moolenaarc236c162008-07-13 17:41:49 +0000843
844OPTIONS: ~
845
846PHP indenting can be altered in several ways by modifying the values of some
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200847global variables:
Bram Moolenaarc236c162008-07-13 17:41:49 +0000848
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200849 *php-comment* *PHP_autoformatcomment*
Bram Moolenaar088e8e32019-08-08 22:15:18 +0200850To not enable auto-formatting of comments by default (if you want to use your
Bram Moolenaarc236c162008-07-13 17:41:49 +0000851own 'formatoptions'): >
852 :let g:PHP_autoformatcomment = 0
853
854Else, 't' will be removed from the 'formatoptions' string and "qrowcb" will be
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200855added, see |fo-table| for more information.
Bram Moolenaarc236c162008-07-13 17:41:49 +0000856-------------
857
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200858 *PHP_outdentSLComments*
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200859To add extra indentation to single-line comments: >
860 :let g:PHP_outdentSLComments = N
861
862With N being the number of 'shiftwidth' to add.
863
864Only single-line comments will be affected such as: >
865 # Comment
866 // Comment
867 /* Comment */
868-------------
869
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200870 *PHP_default_indenting*
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200871To add extra indentation to every PHP lines with N being the number of
Bram Moolenaarc236c162008-07-13 17:41:49 +0000872'shiftwidth' to add: >
873 :let g:PHP_default_indenting = N
874
875For example, with N = 1, this will give:
876>
877 <?php
878 if (!isset($History_lst_sel))
879 if (!isset($History_lst_sel))
880 if (!isset($History_lst_sel)) {
881 $History_lst_sel=0;
882 } else
883 $foo="bar";
884
885 $command_hist = TRUE;
886 ?>
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200887(Notice the extra indentation between the PHP container markers and the code)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000888-------------
889
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200890 *PHP_outdentphpescape*
891To indent PHP escape tags as the surrounding non-PHP code (only affects the
892PHP escape tags): >
893:let g:PHP_outdentphpescape = 0
Bram Moolenaar8408a9a2010-07-30 22:41:22 +0200894-------------
895
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200896 *PHP_removeCRwhenUnix*
Bram Moolenaarc236c162008-07-13 17:41:49 +0000897To automatically remove '\r' characters when the 'fileformat' is set to Unix: >
898 :let g:PHP_removeCRwhenUnix = 1
899-------------
900
Bram Moolenaarbcb98982014-05-01 14:08:19 +0200901 *PHP_BracesAtCodeLevel*
Bram Moolenaarc236c162008-07-13 17:41:49 +0000902To indent braces at the same level than the code they contain: >
903 :let g:PHP_BracesAtCodeLevel = 1
Bram Moolenaar664f3cf2019-12-07 16:03:51 +0100904
Bram Moolenaarc236c162008-07-13 17:41:49 +0000905This will give the following result: >
906 if ($foo)
907 {
908 foo();
909 }
910Instead of: >
911 if ($foo)
912 {
913 foo();
914 }
915
916NOTE: Indenting will be a bit slower if this option is used because some
917 optimizations won't be available.
918-------------
919
Bram Moolenaar54775062019-07-31 21:07:14 +0200920 *PHP_vintage_case_default_indent*
Bram Moolenaarc236c162008-07-13 17:41:49 +0000921To indent 'case:' and 'default:' statements in switch() blocks: >
922 :let g:PHP_vintage_case_default_indent = 1
923
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200924In PHP braces are not required inside 'case/default' blocks therefore 'case:'
925and 'default:' are indented at the same level than the 'switch()' to avoid
926meaningless indentation. You can use the above option to return to the
927traditional way.
Bram Moolenaar0b0f0992018-05-22 21:41:30 +0200928-------------
929
930 *PHP_noArrowMatching*
931By default the indent script will indent multi-line chained calls by matching
932the position of the '->': >
933
934 $user_name_very_long->name()
935 ->age()
936 ->info();
937
938You can revert to the classic way of indenting by setting this option to 1: >
939 :let g:PHP_noArrowMatching = 1
940
941You will obtain the following result: >
942
943 $user_name_very_long->name()
944 ->age()
945 ->info();
946
Bram Moolenaar54775062019-07-31 21:07:14 +0200947-------------
948
949 *PHP_IndentFunctionCallParameters*
950Extra indentation levels to add to parameters in multi-line function calls. >
951 let g:PHP_IndentFunctionCallParameters = 1
952
953Function call arguments will indent 1 extra level. For two-space indentation: >
954
955 function call_the_thing(
956 $with_this,
957 $and_that
958 ) {
959 $this->do_the_thing(
960 $with_this,
961 $and_that
962 );
963 }
964
965-------------
966
967 *PHP_IndentFunctionDeclarationParameters*
Bram Moolenaar2e693a82019-10-16 22:35:02 +0200968Extra indentation levels to add to arguments in multi-line function
969definitions. >
Bram Moolenaar54775062019-07-31 21:07:14 +0200970 let g:PHP_IndentFunctionDeclarationParameters = 1
971
Bram Moolenaar2e693a82019-10-16 22:35:02 +0200972Function arguments in declarations will indent 1 extra level. For two-space
973indentation: >
Bram Moolenaar54775062019-07-31 21:07:14 +0200974
975 function call_the_thing(
976 $with_this,
977 $and_that
978 ) {
979 $this->do_the_thing(
980 $with_this,
981 $and_that
982 );
983 }
Bram Moolenaarc236c162008-07-13 17:41:49 +0000984
985
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000986PYTHON *ft-python-indent*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000987
988The amount of indent can be set for the following situations. The examples
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000989given are the defaults. Note that the variables are set to an expression, so
990that you can change the value of 'shiftwidth' later.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000991
992Indent after an open paren: >
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +0100993 let g:pyindent_open_paren = 'shiftwidth() * 2'
Bram Moolenaar05159a02005-02-26 23:04:13 +0000994Indent after a nested paren: >
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +0100995 let g:pyindent_nested_paren = 'shiftwidth()'
Bram Moolenaar05159a02005-02-26 23:04:13 +0000996Indent for a continuation line: >
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +0100997 let g:pyindent_continue = 'shiftwidth() * 2'
Bram Moolenaar05159a02005-02-26 23:04:13 +0000998
Bram Moolenaare7b1ea02020-08-07 19:54:59 +0200999The method uses |searchpair()| to look back for unclosed parentheses. This
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01001000can sometimes be slow, thus it timeouts after 150 msec. If you notice the
Bram Moolenaar2c64ca12018-10-19 16:22:31 +02001001indenting isn't correct, you can set a larger timeout in msec: >
1002 let g:pyindent_searchpair_timeout = 500
1003
Bram Moolenaarf6b40102019-02-22 15:24:03 +01001004If looking back for unclosed parenthesis is still too slow, especially during
1005a copy-paste operation, or if you don't need indenting inside multi-line
1006parentheses, you can completely disable this feature: >
1007 let g:pyindent_disable_parentheses_indenting = 1
1008
Bram Moolenaar05159a02005-02-26 23:04:13 +00001009
Bram Moolenaar5302d9e2011-09-14 17:55:08 +02001010R *ft-r-indent*
1011
1012Function arguments are aligned if they span for multiple lines. If you prefer
1013do not have the arguments of functions aligned, put in your |vimrc|:
1014>
1015 let r_indent_align_args = 0
1016<
1017All lines beginning with a comment character, #, get the same indentation
1018level of the normal R code. Users of Emacs/ESS may be used to have lines
1019beginning with a single # indented in the 40th column, ## indented as R code,
1020and ### not indented. If you prefer that lines beginning with comment
1021characters are aligned as they are by Emacs/ESS, put in your |vimrc|:
1022>
1023 let r_indent_ess_comments = 1
1024<
1025If you prefer that lines beginning with a single # are aligned at a column
1026different from the 40th one, you should set a new value to the variable
1027r_indent_comment_column, as in the example below:
1028>
1029 let r_indent_comment_column = 30
1030<
1031Any code after a line that ends with "<-" is indented. Emacs/ESS does not
1032indent the code if it is a top level function. If you prefer that the
1033Vim-R-plugin behaves like Emacs/ESS in this regard, put in your |vimrc|:
1034>
1035 let r_indent_ess_compatible = 1
1036<
1037Below is an example of indentation with and without this option enabled:
1038>
1039 ### r_indent_ess_compatible = 1 ### r_indent_ess_compatible = 0
1040 foo <- foo <-
1041 function(x) function(x)
1042 { {
1043 paste(x) paste(x)
1044 } }
1045<
Bram Moolenaarfc65cab2018-08-28 22:58:02 +02001046The code will be indented after lines that match the pattern
1047`'\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$'`. If you want indentation after
1048lines that match a different pattern, you should set the appropriate value of
1049`r_indent_op_pattern` in your |vimrc|.
1050
Bram Moolenaar5302d9e2011-09-14 17:55:08 +02001051
Bram Moolenaar7263a772007-05-10 17:35:54 +00001052SHELL *ft-sh-indent*
1053
1054The amount of indent applied under various circumstances in a shell file can
1055be configured by setting the following keys in the |Dictionary|
1056b:sh_indent_defaults to a specific amount or to a |Funcref| that references a
1057function that will return the amount desired:
1058
1059b:sh_indent_options['default'] Default amount of indent.
1060
1061b:sh_indent_options['continuation-line']
1062 Amount of indent to add to a continued line.
1063
1064b:sh_indent_options['case-labels']
1065 Amount of indent to add for case labels.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001066 (not actually implemented)
Bram Moolenaar7263a772007-05-10 17:35:54 +00001067
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001068b:sh_indent_options['case-statements']
Bram Moolenaar7263a772007-05-10 17:35:54 +00001069 Amount of indent to add for case statements.
1070
1071b:sh_indent_options['case-breaks']
1072 Amount of indent to add (or more likely
1073 remove) for case breaks.
1074
Bram Moolenaarda2303d2005-08-30 21:55:26 +00001075VERILOG *ft-verilog-indent*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076
1077General block statements such as if, for, case, always, initial, function,
1078specify and begin, etc., are indented. The module block statements (first
1079level blocks) are not indented by default. you can turn on the indent with
1080setting a variable in the .vimrc as follows: >
1081
1082 let b:verilog_indent_modules = 1
1083
1084then the module blocks will be indented. To stop this, remove the variable: >
1085
1086 :unlet b:verilog_indent_modules
1087
1088To set the variable only for Verilog file. The following statements can be
1089used: >
1090
1091 au BufReadPost * if exists("b:current_syntax")
1092 au BufReadPost * if b:current_syntax == "verilog"
1093 au BufReadPost * let b:verilog_indent_modules = 1
1094 au BufReadPost * endif
1095 au BufReadPost * endif
1096
1097Furthermore, setting the variable b:verilog_indent_width to change the
1098indenting width (default is 'shiftwidth'): >
1099
1100 let b:verilog_indent_width = 4
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01001101 let b:verilog_indent_width = shiftwidth() * 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102
1103In addition, you can turn the verbose mode for debug issue: >
1104
1105 let b:verilog_indent_verbose = 1
1106
1107Make sure to do ":set cmdheight=2" first to allow the display of the message.
1108
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001109
Bram Moolenaar3577c6f2008-06-24 21:16:56 +00001110VHDL *ft-vhdl-indent*
1111
1112Alignment of generic/port mapping statements are performed by default. This
1113causes the following alignment example: >
1114
1115 ENTITY sync IS
1116 PORT (
1117 clk : IN STD_LOGIC;
1118 reset_n : IN STD_LOGIC;
1119 data_input : IN STD_LOGIC;
1120 data_out : OUT STD_LOGIC
1121 );
1122 END ENTITY sync;
1123
1124To turn this off, add >
1125
1126 let g:vhdl_indent_genportmap = 0
1127
1128to the .vimrc file, which causes the previous alignment example to change: >
1129
1130 ENTITY sync IS
1131 PORT (
1132 clk : IN STD_LOGIC;
1133 reset_n : IN STD_LOGIC;
1134 data_input : IN STD_LOGIC;
1135 data_out : OUT STD_LOGIC
1136 );
1137 END ENTITY sync;
1138
1139----------------------------------------
1140
1141Alignment of right-hand side assignment "<=" statements are performed by
1142default. This causes the following alignment example: >
1143
1144 sig_out <= (bus_a(1) AND
1145 (sig_b OR sig_c)) OR
1146 (bus_a(0) AND sig_d);
1147
1148To turn this off, add >
1149
1150 let g:vhdl_indent_rhsassign = 0
1151
1152to the .vimrc file, which causes the previous alignment example to change: >
1153
1154 sig_out <= (bus_a(1) AND
1155 (sig_b OR sig_c)) OR
1156 (bus_a(0) AND sig_d);
1157
1158----------------------------------------
1159
1160Full-line comments (lines that begin with "--") are indented to be aligned with
1161the very previous line's comment, PROVIDED that a whitespace follows after
1162"--".
1163
1164For example: >
1165
1166 sig_a <= sig_b; -- start of a comment
1167 -- continuation of the comment
1168 -- more of the same comment
1169
1170While in Insert mode, after typing "-- " (note the space " "), hitting CTRL-F
1171will align the current "-- " with the previous line's "--".
1172
1173If the very previous line does not contain "--", THEN the full-line comment
1174will be aligned with the start of the next non-blank line that is NOT a
1175full-line comment.
1176
1177Indenting the following code: >
1178
1179 sig_c <= sig_d; -- comment 0
1180 -- comment 1
1181 -- comment 2
1182 --debug_code:
1183 --PROCESS(debug_in)
1184 --BEGIN
1185 -- FOR i IN 15 DOWNTO 0 LOOP
1186 -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i);
1187 -- END LOOP;
1188 --END PROCESS debug_code;
1189
1190 -- comment 3
1191 sig_e <= sig_f; -- comment 4
1192 -- comment 5
1193
1194results in: >
1195
1196 sig_c <= sig_d; -- comment 0
1197 -- comment 1
1198 -- comment 2
1199 --debug_code:
1200 --PROCESS(debug_in)
1201 --BEGIN
1202 -- FOR i IN 15 DOWNTO 0 LOOP
1203 -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i);
1204 -- END LOOP;
1205 --END PROCESS debug_code;
1206
1207 -- comment 3
1208 sig_e <= sig_f; -- comment 4
1209 -- comment 5
1210
1211Notice that "--debug_code:" does not align with "-- comment 2"
1212because there is no whitespace that follows after "--" in "--debug_code:".
1213
1214Given the dynamic nature of indenting comments, indenting should be done TWICE.
1215On the first pass, code will be indented. On the second pass, full-line
1216comments will be indented according to the correctly indented code.
1217
1218
Bram Moolenaarda2303d2005-08-30 21:55:26 +00001219VIM *ft-vim-indent*
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001220
1221For indenting Vim scripts there is one variable that specifies the amount of
1222indent for a continuation line, a line that starts with a backslash: >
1223
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01001224 :let g:vim_indent_cont = shiftwidth() * 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001225
1226Three times shiftwidth is the default value.
1227
1228
Bram Moolenaar91f84f62018-07-29 15:07:52 +02001229 vim:tw=78:ts=8:noet:ft=help:norl: