Mercurial > vim
annotate runtime/doc/indent.txt @ 28353:8bc8071928ed v8.2.4702
patch 8.2.4702: C++ scope labels are hard-coded
Commit: https://github.com/vim/vim/commit/3506cf34c17c5eae6c2d1317db1fcd5a8493c288
Author: Tom Praschan <13141438+tom-anders@users.noreply.github.com>
Date: Thu Apr 7 12:39:08 2022 +0100
patch 8.2.4702: C++ scope labels are hard-coded
Problem: C++ scope labels are hard-coded.
Solution: Add 'cinscopedecls' to define the labels. (Rom Praschan,
closes #10109)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 07 Apr 2022 13:45:04 +0200 |
parents | 4789f29c9595 |
children | 6dd88e45d47d |
rev | line source |
---|---|
27492 | 1 *indent.txt* For Vim version 8.2. Last change: 2022 Jan 31 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 This file is about indenting C programs and other files. | |
8 | |
1620 | 9 1. Indenting C style programs |C-indenting| |
7 | 10 2. Indenting by expression |indent-expression| |
11 | |
12 ============================================================================== | |
1620 | 13 1. Indenting C style programs *C-indenting* |
7 | 14 |
1620 | 15 The basics for C style indenting are explained in section |30.2| of the user |
16 manual. | |
7 | 17 |
1620 | 18 Vim has options for automatically indenting C style program files. Many |
19 programming languages including Java and C++ follow very closely the | |
20 formatting conventions established with C. These options affect only the | |
21 indent and do not perform other formatting. There are additional options that | |
22 affect other kinds of formatting as well as indenting, see |format-comments|, | |
23 |fo-table|, |gq| and |formatting| for the main ones. | |
7 | 24 |
25 Note that this will not work when the |+smartindent| or |+cindent| features | |
26 have been disabled at compile time. | |
27 | |
1620 | 28 There are in fact four main methods available for indentation, each one |
29 overrides the previous if it is enabled, or non-empty for 'indentexpr': | |
7 | 30 '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|. | |
38 The rest of this section describes the 'cindent' option. | |
39 | |
40 Note that 'cindent' indenting does not work for every code scenario. Vim | |
829 | 41 is not a C compiler: it does not recognize all syntax. One requirement is |
42 that toplevel functions have a '{' in the first column. Otherwise they are | |
43 easily confused with declarations. | |
7 | 44 |
28353
8bc8071928ed
patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
45 These five options control C program indenting: |
7 | 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. | |
28353
8bc8071928ed
patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
50 'cinscopedecls' Defines strings that are recognized as a C++ scope declaration. |
7 | 51 |
52 If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using | |
53 Vim's built-in algorithm rather than calling an external program. | |
54 | |
55 See |autocommand| for how to set the 'cindent' option automatically for C code | |
56 files and reset it for others. | |
57 | |
58 *cinkeys-format* *indentkeys-format* | |
59 The 'cinkeys' option is a string that controls Vim's indenting in response to | |
60 typing certain characters or commands in certain contexts. Note that this not | |
61 only triggers C-indenting. When 'indentexpr' is not empty 'indentkeys' is | |
62 used instead. The format of 'cinkeys' and 'indentkeys' is equal. | |
63 | |
15701
9cd11f6beb70
patch 8.1.0858: 'indentkeys' and 'cinkeys' defaults are different
Bram Moolenaar <Bram@vim.org>
parents:
15033
diff
changeset
|
64 The default is "0{,0},0),0],:,0#,!^F,o,O,e" which specifies that indenting |
9cd11f6beb70
patch 8.1.0858: 'indentkeys' and 'cinkeys' defaults are different
Bram Moolenaar <Bram@vim.org>
parents:
15033
diff
changeset
|
65 occurs as follows: |
7 | 66 |
67 "0{" if you type '{' as the first character in a line | |
68 "0}" if you type '}' as the first character in a line | |
69 "0)" if you type ')' as the first character in a line | |
15701
9cd11f6beb70
patch 8.1.0858: 'indentkeys' and 'cinkeys' defaults are different
Bram Moolenaar <Bram@vim.org>
parents:
15033
diff
changeset
|
70 "0]" if you type ']' as the first character in a line |
7 | 71 ":" if you type ':' after a label or case statement |
72 "0#" if you type '#' as the first character in a line | |
73 "!^F" if you type CTRL-F (which is not inserted) | |
74 "o" if you type a <CR> anywhere or use the "o" command (not in | |
75 insert mode!) | |
76 "O" if you use the "O" command (not in insert mode!) | |
77 "e" if you type the second 'e' for an "else" at the start of a | |
78 line | |
79 | |
818 | 80 Characters that can precede each key: *i_CTRL-F* |
7 | 81 ! When a '!' precedes the key, Vim will not insert the key but will |
82 instead reindent the current line. This allows you to define a | |
83 command key for reindenting the current line. CTRL-F is the default | |
84 key for this. Be careful if you define CTRL-I for this because CTRL-I | |
85 is the ASCII code for <Tab>. | |
86 * When a '*' precedes the key, Vim will reindent the line before | |
87 inserting the key. If 'cinkeys' contains "*<Return>", Vim reindents | |
88 the current line before opening a new line. | |
89 0 When a zero precedes the key (but appears after '!' or '*') Vim will | |
90 reindent the line only if the key is the first character you type in | |
91 the line. When used before "=" Vim will only reindent the line if | |
92 there is only white space before the word. | |
93 | |
94 When neither '!' nor '*' precedes the key, Vim reindents the line after you | |
95 type the key. So ';' sets the indentation of a line which includes the ';'. | |
96 | |
97 Special key names: | |
98 <> Angle brackets mean spelled-out names of keys. For example: "<Up>", | |
99 "<Ins>" (see |key-notation|). | |
100 ^ Letters preceded by a caret (^) are control characters. For example: | |
101 "^F" is CTRL-F. | |
102 o Reindent a line when you use the "o" command or when Vim opens a new | |
103 line below the current one (e.g., when you type <Enter> in insert | |
104 mode). | |
105 O Reindent a line when you use the "O" command. | |
106 e Reindent a line that starts with "else" when you type the second 'e'. | |
107 : Reindent a line when a ':' is typed which is after a label or case | |
108 statement. Don't reindent for a ":" in "class::method" for C++. To | |
109 Reindent for any ":", use "<:>". | |
110 =word Reindent when typing the last character of "word". "word" may | |
111 actually be part of another word. Thus "=end" would cause reindenting | |
112 when typing the "d" in "endif" or "endwhile". But not when typing | |
113 "bend". Also reindent when completion produces a word that starts | |
114 with "word". "0=word" reindents when there is only white space before | |
115 the word. | |
116 =~word Like =word, but ignore case. | |
117 | |
118 If you really want to reindent when you type 'o', 'O', 'e', '0', '<', '>', | |
119 '*', ':' or '!', use "<o>", "<O>", "<e>", "<0>", "<<>", "<>>", "<*>", "<:>" or | |
120 "<!>", respectively, for those keys. | |
121 | |
122 For an emacs-style indent mode where lines aren't indented every time you | |
1247 | 123 press <Enter> but only if you press <Tab>, I suggest: |
7 | 124 :set cinkeys=0{,0},:,0#,!<Tab>,!^F |
125 You might also want to switch off 'autoindent' then. | |
126 | |
127 Note: If you change the current line's indentation manually, Vim ignores the | |
128 cindent settings for that line. This prevents vim from reindenting after you | |
129 have changed the indent by typing <BS>, <Tab>, or <Space> in the indent or | |
130 used CTRL-T or CTRL-D. | |
131 | |
132 *cinoptions-values* | |
2857 | 133 The 'cinoptions' option sets how Vim performs indentation. The value after |
134 the option character can be one of these (N is any number): | |
135 N indent N spaces | |
136 -N indent N spaces to the left | |
3082 | 137 Ns N times 'shiftwidth' spaces |
138 -Ns N times 'shiftwidth' spaces to the left | |
2857 | 139 |
140 In the list below, | |
7 | 141 "N" represents a number of your choice (the number can be negative). When |
142 there is an 's' after the number, Vim multiplies the number by 'shiftwidth': | |
143 "1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc. You can use a | |
2857 | 144 decimal point, too: "-0.5s" is minus half a 'shiftwidth'. |
145 The examples below assume a 'shiftwidth' of 4. | |
146 *cino->* | |
7 | 147 >N Amount added for "normal" indent. Used after a line that should |
148 increase the indent (lines starting with "if", an opening brace, | |
149 etc.). (default 'shiftwidth'). | |
150 | |
151 cino= cino=>2 cino=>2s > | |
152 if (cond) if (cond) if (cond) | |
153 { { { | |
154 foo; foo; foo; | |
155 } } } | |
156 < | |
2857 | 157 *cino-e* |
7 | 158 eN Add N to the prevailing indent inside a set of braces if the |
159 opening brace at the End of the line (more precise: is not the | |
160 first character in a line). This is useful if you want a | |
161 different indent when the '{' is at the start of the line from | |
162 when '{' is at the end of the line. (default 0). | |
163 | |
164 cino= cino=e2 cino=e-2 > | |
165 if (cond) { if (cond) { if (cond) { | |
166 foo; foo; foo; | |
167 } } } | |
168 else else else | |
169 { { { | |
170 bar; bar; bar; | |
171 } } } | |
172 < | |
2857 | 173 *cino-n* |
7 | 174 nN Add N to the prevailing indent for a statement after an "if", |
175 "while", etc., if it is NOT inside a set of braces. This is | |
176 useful if you want a different indent when there is no '{' | |
177 before the statement from when there is a '{' before it. | |
178 (default 0). | |
179 | |
180 cino= cino=n2 cino=n-2 > | |
181 if (cond) if (cond) if (cond) | |
182 foo; foo; foo; | |
183 else else else | |
184 { { { | |
185 bar; bar; bar; | |
186 } } } | |
187 < | |
2857 | 188 *cino-f* |
7 | 189 fN Place the first opening brace of a function or other block in |
190 column N. This applies only for an opening brace that is not | |
191 inside other braces and is at the start of the line. What comes | |
192 after the brace is put relative to this brace. (default 0). | |
193 | |
194 cino= cino=f.5s cino=f1s > | |
195 func() func() func() | |
196 { { { | |
197 int foo; int foo; int foo; | |
198 < | |
2857 | 199 *cino-{* |
7 | 200 {N Place opening braces N characters from the prevailing indent. |
201 This applies only for opening braces that are inside other | |
202 braces. (default 0). | |
203 | |
204 cino= cino={.5s cino={1s > | |
205 if (cond) if (cond) if (cond) | |
206 { { { | |
207 foo; foo; foo; | |
208 < | |
2857 | 209 *cino-}* |
7 | 210 }N Place closing braces N characters from the matching opening |
211 brace. (default 0). | |
212 | |
213 cino= cino={2,}-0.5s cino=}2 > | |
214 if (cond) if (cond) if (cond) | |
215 { { { | |
216 foo; foo; foo; | |
217 } } } | |
218 < | |
2857 | 219 *cino-^* |
7 | 220 ^N Add N to the prevailing indent inside a set of braces if the |
221 opening brace is in column 0. This can specify a different | |
222 indent for whole of a function (some may like to set it to a | |
223 negative number). (default 0). | |
224 | |
225 cino= cino=^-2 cino=^-s > | |
226 func() func() func() | |
227 { { { | |
228 if (cond) if (cond) if (cond) | |
229 { { { | |
230 a = b; a = b; a = b; | |
231 } } } | |
232 } } } | |
233 < | |
2857 | 234 *cino-L* |
2328
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
235 LN Controls placement of jump labels. If N is negative, the label |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
236 will be placed at column 1. If N is non-negative, the indent of |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
237 the label will be the prevailing indent minus N. (default -1). |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
238 |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
239 cino= cino=L2 cino=Ls > |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
240 func() func() func() |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
241 { { { |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
242 { { { |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
243 stmt; stmt; stmt; |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
244 LABEL: LABEL: LABEL: |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
245 } } } |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
246 } } } |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
247 < |
2857 | 248 *cino-:* |
7 | 249 :N Place case labels N characters from the indent of the switch(). |
250 (default 'shiftwidth'). | |
251 | |
252 cino= cino=:0 > | |
253 switch (x) switch(x) | |
254 { { | |
255 case 1: case 1: | |
256 a = b; a = b; | |
257 default: default: | |
258 } } | |
259 < | |
2857 | 260 *cino-=* |
7 | 261 =N Place statements occurring after a case label N characters from |
262 the indent of the label. (default 'shiftwidth'). | |
263 | |
264 cino= cino==10 > | |
265 case 11: case 11: a = a + 1; | |
266 a = a + 1; b = b + 1; | |
267 < | |
2857 | 268 *cino-l* |
7 | 269 lN If N != 0 Vim will align with a case label instead of the |
270 statement after it in the same line. | |
271 | |
272 cino= cino=l1 > | |
273 switch (a) { switch (a) { | |
274 case 1: { case 1: { | |
275 break; break; | |
276 } } | |
277 < | |
2857 | 278 *cino-b* |
7 | 279 bN If N != 0 Vim will align a final "break" with the case label, |
236 | 280 so that case..break looks like a sort of block. (default: 0). |
2662 | 281 When using 1, consider adding "0=break" to 'cinkeys'. |
7 | 282 |
283 cino= cino=b1 > | |
284 switch (x) switch(x) | |
285 { { | |
286 case 1: case 1: | |
287 a = b; a = b; | |
288 break; break; | |
289 | |
290 default: default: | |
291 a = 0; a = 0; | |
292 break; break; | |
293 } } | |
294 < | |
2857 | 295 *cino-g* |
7 | 296 gN Place C++ scope declarations N characters from the indent of the |
28353
8bc8071928ed
patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
297 block they are in. (default 'shiftwidth'). By default, a scope |
8bc8071928ed
patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
298 declaration is "public:", "protected:" or "private:". This can |
8bc8071928ed
patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents:
27492
diff
changeset
|
299 be adjusted with the 'cinscopedecls' option. |
7 | 300 |
301 cino= cino=g0 > | |
302 { { | |
303 public: public: | |
304 a = b; a = b; | |
305 private: private: | |
306 } } | |
307 < | |
2857 | 308 *cino-h* |
7 | 309 hN Place statements occurring after a C++ scope declaration N |
310 characters from the indent of the label. (default | |
311 'shiftwidth'). | |
312 | |
313 cino= cino=h10 > | |
314 public: public: a = a + 1; | |
315 a = a + 1; b = b + 1; | |
316 < | |
2857 | 317 *cino-N* |
318 NN Indent inside C++ namespace N characters extra compared to a | |
319 normal block. (default 0). | |
320 | |
321 cino= cino=N-s > | |
322 namespace { namespace { | |
323 void function(); void function(); | |
324 } } | |
325 | |
326 namespace my namespace my | |
327 { { | |
328 void function(); void function(); | |
329 } } | |
330 < | |
11087
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
331 *cino-E* |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
332 EN Indent inside C++ linkage specifications (extern "C" or |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
333 extern "C++") N characters extra compared to a normal block. |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
334 (default 0). |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
335 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
336 cino= cino=E-s > |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
337 extern "C" { extern "C" { |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
338 void function(); void function(); |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
339 } } |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
340 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
341 extern "C" extern "C" |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
342 { { |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
343 void function(); void function(); |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
344 } } |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
345 < |
2857 | 346 *cino-p* |
7 | 347 pN Parameter declarations for K&R-style function declarations will |
348 be indented N characters from the margin. (default | |
349 'shiftwidth'). | |
350 | |
351 cino= cino=p0 cino=p2s > | |
352 func(a, b) func(a, b) func(a, b) | |
353 int a; int a; int a; | |
354 char b; char b; char b; | |
355 < | |
2857 | 356 *cino-t* |
7 | 357 tN Indent a function return type declaration N characters from the |
358 margin. (default 'shiftwidth'). | |
359 | |
360 cino= cino=t0 cino=t7 > | |
361 int int int | |
362 func() func() func() | |
363 < | |
2857 | 364 *cino-i* |
843 | 365 iN Indent C++ base class declarations and constructor |
7 | 366 initializations, if they start in a new line (otherwise they |
367 are aligned at the right side of the ':'). | |
368 (default 'shiftwidth'). | |
369 | |
370 cino= cino=i0 > | |
371 class MyClass : class MyClass : | |
372 public BaseClass public BaseClass | |
373 {} {} | |
374 MyClass::MyClass() : MyClass::MyClass() : | |
375 BaseClass(3) BaseClass(3) | |
376 {} {} | |
377 < | |
2857 | 378 *cino-+* |
2725 | 379 +N Indent a continuation line (a line that spills onto the next) |
380 inside a function N additional characters. (default | |
381 'shiftwidth'). | |
382 Outside of a function, when the previous line ended in a | |
383 backslash, the 2 * N is used. | |
7 | 384 |
385 cino= cino=+10 > | |
386 a = b + 9 * a = b + 9 * | |
387 c; c; | |
388 < | |
2857 | 389 *cino-c* |
7 | 390 cN Indent comment lines after the comment opener, when there is no |
391 other text with which to align, N characters from the comment | |
392 opener. (default 3). See also |format-comments|. | |
393 | |
394 cino= cino=c5 > | |
395 /* /* | |
396 text. text. | |
397 */ */ | |
398 < | |
2857 | 399 *cino-C* |
7 | 400 CN When N is non-zero, indent comment lines by the amount specified |
401 with the c flag above even if there is other text behind the | |
402 comment opener. (default 0). | |
403 | |
404 cino=c0 cino=c0,C1 > | |
405 /******** /******** | |
406 text. text. | |
407 ********/ ********/ | |
408 < (Example uses ":set comments& comments-=s1:/* comments^=s0:/*") | |
409 | |
2857 | 410 *cino-/* |
236 | 411 /N Indent comment lines N characters extra. (default 0). |
7 | 412 cino= cino=/4 > |
413 a = b; a = b; | |
414 /* comment */ /* comment */ | |
415 c = d; c = d; | |
416 < | |
2857 | 417 *cino-(* |
7 | 418 (N When in unclosed parentheses, indent N characters from the line |
21676 | 419 with the unclosed parenthesis. Add a 'shiftwidth' for every |
13589 | 420 extra unclosed parentheses. When N is 0 or the unclosed |
21676 | 421 parenthesis is the first non-white character in its line, line |
13589 | 422 up with the next non-white character after the unclosed |
21676 | 423 parenthesis. (default 'shiftwidth' * 2). |
7 | 424 |
425 cino= cino=(0 > | |
426 if (c1 && (c2 || if (c1 && (c2 || | |
427 c3)) c3)) | |
428 foo; foo; | |
429 if (c1 && if (c1 && | |
430 (c2 || c3)) (c2 || c3)) | |
431 { { | |
432 < | |
2857 | 433 *cino-u* |
13589 | 434 uN Same as (N, but for one nesting level deeper. |
435 (default 'shiftwidth'). | |
7 | 436 |
437 cino= cino=u2 > | |
438 if (c123456789 if (c123456789 | |
439 && (c22345 && (c22345 | |
440 || c3)) || c3)) | |
441 < | |
2857 | 442 *cino-U* |
7 | 443 UN When N is non-zero, do not ignore the indenting specified by |
21676 | 444 ( or u in case that the unclosed parenthesis is the first |
7 | 445 non-white character in its line. (default 0). |
446 | |
447 cino= or cino=(s cino=(s,U1 > | |
448 c = c1 && c = c1 && | |
449 ( ( | |
450 c2 || c2 || | |
451 c3 c3 | |
452 ) && c4; ) && c4; | |
453 < | |
3082 | 454 *cino-w* |
7 | 455 wN When in unclosed parentheses and N is non-zero and either |
456 using "(0" or "u0", respectively, or using "U0" and the unclosed | |
21676 | 457 parenthesis is the first non-white character in its line, line |
458 up with the character immediately after the unclosed parenthesis | |
7 | 459 rather than the first non-white character. (default 0). |
460 | |
461 cino=(0 cino=(0,w1 > | |
462 if ( c1 if ( c1 | |
463 && ( c2 && ( c2 | |
464 || c3)) || c3)) | |
465 foo; foo; | |
466 < | |
2857 | 467 *cino-W* |
7 | 468 WN When in unclosed parentheses and N is non-zero and either |
21676 | 469 using "(0" or "u0", respectively and the unclosed parenthesis is |
7 | 470 the last non-white character in its line and it is not the |
21676 | 471 closing parenthesis, indent the following line N characters |
7 | 472 relative to the outer context (i.e. start of the line or the |
21676 | 473 next unclosed parenthesis). (default: 0). |
7 | 474 |
475 cino=(0 cino=(0,W4 > | |
476 a_long_line( a_long_line( | |
477 argument, argument, | |
478 argument); argument); | |
479 a_short_line(argument, a_short_line(argument, | |
480 argument); argument); | |
481 < | |
3454 | 482 *cino-k* |
483 kN When in unclosed parentheses which follow "if", "for" or | |
484 "while" and N is non-zero, overrides the behaviour defined by | |
485 "(N": causes the indent to be N characters relative to the outer | |
486 context (i.e. the line where "if", "for" or "while" is). Has | |
487 no effect on deeper levels of nesting. Affects flags like "wN" | |
488 only for the "if", "for" and "while" conditions. If 0, defaults | |
489 to behaviour defined by the "(N" flag. (default: 0). | |
490 | |
491 cino=(0 cino=(0,ks > | |
492 if (condition1 if (condition1 | |
493 && condition2) && condition2) | |
494 action(); action(); | |
495 function(argument1 function(argument1 | |
496 && argument2); && argument2); | |
497 < | |
2857 | 498 *cino-m* |
7 | 499 mN When N is non-zero, line up a line starting with a closing |
21676 | 500 parenthesis with the first character of the line with the |
501 matching opening parenthesis. (default 0). | |
7 | 502 |
503 cino=(s cino=(s,m1 > | |
504 c = c1 && ( c = c1 && ( | |
505 c2 || c2 || | |
506 c3 c3 | |
507 ) && c4; ) && c4; | |
508 if ( if ( | |
509 c1 && c2 c1 && c2 | |
510 ) ) | |
511 foo; foo; | |
512 < | |
2857 | 513 *cino-M* |
829 | 514 MN When N is non-zero, line up a line starting with a closing |
21676 | 515 parenthesis with the first character of the previous line. |
829 | 516 (default 0). |
517 | |
518 cino= cino=M1 > | |
519 if (cond1 && if (cond1 && | |
856 | 520 cond2 cond2 |
521 ) ) | |
829 | 522 < |
2857 | 523 *java-cinoptions* *java-indenting* *cino-j* |
2965 | 524 jN Indent Java anonymous classes correctly. Also works well for |
525 Javascript. The value 'N' is currently unused but must be | |
526 non-zero (e.g. 'j1'). 'j1' will indent for example the | |
527 following code snippet correctly: > | |
7 | 528 |
529 object.add(new ChangeListener() { | |
530 public void stateChanged(ChangeEvent e) { | |
531 do_something(); | |
532 } | |
533 }); | |
534 < | |
2857 | 535 *javascript-cinoptions* *javascript-indenting* *cino-J* |
2297
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
536 JN Indent JavaScript object declarations correctly by not confusing |
18831 | 537 them with labels. The value 'N' is currently unused but must be |
2965 | 538 non-zero (e.g. 'J1'). If you enable this you probably also want |
539 to set |cino-j|. > | |
2297
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
540 |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
541 var bar = { |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
542 foo: { |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
543 that: this, |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
544 some: ok, |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
545 }, |
18831 | 546 "bar":{ |
2297
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
547 a : 2, |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
548 b: "123abc", |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
549 x: 4, |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
550 "y": 5 |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
551 } |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
552 } |
5ffe000a9ecf
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
553 < |
2857 | 554 *cino-)* |
7 | 555 )N Vim searches for unclosed parentheses at most N lines away. |
556 This limits the time needed to search for parentheses. (default | |
557 20 lines). | |
558 | |
2857 | 559 *cino-star* |
7 | 560 *N Vim searches for unclosed comments at most N lines away. This |
561 limits the time needed to search for the start of a comment. | |
3830 | 562 If your /* */ comments stop indenting after N lines this is the |
2788 | 563 value you will want to change. |
2072 | 564 (default 70 lines). |
7 | 565 |
2857 | 566 *cino-#* |
5438 | 567 #N When N is non-zero recognize shell/Perl comments starting with |
568 '#', do not recognize preprocessor lines; allow right-shifting | |
569 lines that start with "#". | |
570 When N is zero (default): don't recognize '#' comments, do | |
571 recognize preprocessor lines; right-shifting lines that start | |
572 with "#" does not work. | |
1096 | 573 |
21676 | 574 *cino-P* |
20621
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
575 PN When N is non-zero recognize C pragmas, and indent them like any |
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
576 other code; does not concern other preprocessor directives. |
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
577 When N is zero (default): don't recognize C pragmas, treating |
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
578 them like every other preprocessor directive. |
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
579 |
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
580 |
7 | 581 The defaults, spelled out in full, are: |
11087
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
582 cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,E0,ps,ts,is,+s, |
20621
d30b16692ce0
patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
583 c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0,P0 |
7 | 584 |
585 Vim puts a line in column 1 if: | |
5438 | 586 - It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'. |
7 | 587 - It starts with a label (a keyword followed by ':', other than "case" and |
2328
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
588 "default") and 'cinoptions' does not contain an 'L' entry with a positive |
15379284e55a
Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
589 value. |
7 | 590 - Any combination of indentations causes the line to have less than 0 |
591 indentation. | |
592 | |
593 ============================================================================== | |
594 2. Indenting by expression *indent-expression* | |
595 | |
596 The basics for using flexible indenting are explained in section |30.3| of the | |
597 user manual. | |
598 | |
599 If you want to write your own indent file, it must set the 'indentexpr' | |
14999 | 600 option. Setting the 'indentkeys' option is often useful. |
601 See the $VIMRUNTIME/indent/README.txt file for hints. | |
602 See the $VIMRUNTIME/indent directory for examples. | |
7 | 603 |
604 | |
605 REMARKS ABOUT SPECIFIC INDENT FILES ~ | |
606 | |
607 | |
4098 | 608 CLOJURE *ft-clojure-indent* *clojure-indent* |
609 | |
610 Clojure indentation differs somewhat from traditional Lisps, due in part to | |
611 the use of square and curly brackets, and otherwise by community convention. | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
612 These conventions are not universally followed, so the Clojure indent script |
26100 | 613 offers a few configuration options. |
4098 | 614 |
26100 | 615 (If the current Vim does not include |searchpairpos()|, the indent script falls |
616 back to normal 'lisp' indenting, and the following options are ignored.) | |
617 | |
4098 | 618 |
619 *g:clojure_maxlines* | |
620 | |
26100 | 621 Sets maximum scan distance of `searchpairpos()`. Larger values trade |
622 performance for correctness when dealing with very long forms. A value of | |
623 0 will scan without limits. The default is 300. | |
624 | |
625 | |
4098 | 626 *g:clojure_fuzzy_indent* |
627 *g:clojure_fuzzy_indent_patterns* | |
628 *g:clojure_fuzzy_indent_blacklist* | |
629 | |
630 The 'lispwords' option is a list of comma-separated words that mark special | |
26100 | 631 forms whose subforms should be indented with two spaces. |
4098 | 632 |
633 For example: | |
634 > | |
635 (defn bad [] | |
636 "Incorrect indentation") | |
637 | |
638 (defn good [] | |
639 "Correct indentation") | |
640 < | |
641 If you would like to specify 'lispwords' with a |pattern| instead, you can use | |
642 the fuzzy indent feature: | |
643 > | |
644 " Default | |
645 let g:clojure_fuzzy_indent = 1 | |
646 let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let'] | |
647 let g:clojure_fuzzy_indent_blacklist = | |
648 \ ['-fn$', '\v^with-%(meta|out-str|loading-context)$'] | |
649 < | |
650 |g:clojure_fuzzy_indent_patterns| and |g:clojure_fuzzy_indent_blacklist| are | |
26100 | 651 lists of patterns that will be matched against the unqualified symbol at the |
652 head of a list. This means that a pattern like `"^foo"` will match all these | |
653 candidates: `foobar`, `my.ns/foobar`, and `#'foobar`. | |
4098 | 654 |
655 Each candidate word is tested for special treatment in this order: | |
656 | |
657 1. Return true if word is literally in 'lispwords' | |
658 2. Return false if word matches a pattern in | |
659 |g:clojure_fuzzy_indent_blacklist| | |
660 3. Return true if word matches a pattern in | |
661 |g:clojure_fuzzy_indent_patterns| | |
662 4. Return false and indent normally otherwise | |
663 | |
26100 | 664 |
4098 | 665 *g:clojure_special_indent_words* |
666 | |
26100 | 667 Some forms in Clojure are indented such that every subform is indented by only |
668 two spaces, regardless of 'lispwords'. If you have a custom construct that | |
669 should be indented in this idiosyncratic fashion, you can add your symbols to | |
670 the default list below. | |
4098 | 671 > |
672 " Default | |
673 let g:clojure_special_indent_words = | |
674 \ 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn' | |
675 < | |
26100 | 676 |
4098 | 677 *g:clojure_align_multiline_strings* |
678 | |
26100 | 679 Align subsequent lines in multi-line strings to the column after the opening |
4098 | 680 quote, instead of the same column. |
681 | |
682 For example: | |
683 > | |
684 (def default | |
685 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do | |
686 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut | |
687 enim ad minim veniam, quis nostrud exercitation ullamco laboris | |
688 nisi ut aliquip ex ea commodo consequat.") | |
689 | |
690 (def aligned | |
691 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do | |
692 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut | |
693 enim ad minim veniam, quis nostrud exercitation ullamco laboris | |
694 nisi ut aliquip ex ea commodo consequat.") | |
695 < | |
26100 | 696 |
5577 | 697 *g:clojure_align_subforms* |
698 | |
699 By default, parenthesized compound forms that look like function calls and | |
700 whose head subform is on its own line have subsequent subforms indented by | |
701 two spaces relative to the opening paren: | |
702 > | |
703 (foo | |
704 bar | |
705 baz) | |
706 < | |
26100 | 707 Setting this option to `1` changes this behaviour so that all subforms are |
708 aligned to the same column, emulating the default behaviour of | |
709 clojure-mode.el: | |
5577 | 710 > |
711 (foo | |
712 bar | |
713 baz) | |
714 < | |
4098 | 715 |
501 | 716 FORTRAN *ft-fortran-indent* |
7 | 717 |
2908 | 718 Block if, select case, where, and forall constructs are indented. So are |
719 type, interface, associate, block, and enum constructs. The indenting of | |
720 subroutines, functions, modules, and program blocks is optional. Comments, | |
721 labelled statements and continuation lines are indented if the Fortran is in | |
722 free source form, whereas they are not indented if the Fortran is in fixed | |
723 source form because of the left margin requirements. Hence manual indent | |
724 corrections will be necessary for labelled statements and continuation lines | |
725 when fixed source form is being used. For further discussion of the method | |
726 used for the detection of source format see |ft-fortran-syntax|. | |
7 | 727 |
728 Do loops ~ | |
236 | 729 All do loops are left unindented by default. Do loops can be unstructured in |
7 | 730 Fortran with (possibly multiple) loops ending on a labelled executable |
236 | 731 statement of almost arbitrary type. Correct indentation requires |
732 compiler-quality parsing. Old code with do loops ending on labelled statements | |
7 | 733 of arbitrary type can be indented with elaborate programs such as Tidy |
236 | 734 (http://www.unb.ca/chem/ajit/f_tidy.htm). Structured do/continue loops are |
7 | 735 also left unindented because continue statements are also used for purposes |
236 | 736 other than ending a do loop. Programs such as Tidy can convert structured |
737 do/continue loops to the do/enddo form. Do loops of the do/enddo variety can | |
738 be indented. If you use only structured loops of the do/enddo form, you should | |
7 | 739 declare this by setting the fortran_do_enddo variable in your .vimrc as |
740 follows > | |
741 | |
742 let fortran_do_enddo=1 | |
743 | |
236 | 744 in which case do loops will be indented. If all your loops are of do/enddo |
7 | 745 type only in, say, .f90 files, then you should set a buffer flag with an |
746 autocommand such as > | |
747 | |
748 au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1 | |
749 | |
750 to get do loops indented in .f90 files and left alone in Fortran files with | |
751 other extensions such as .for. | |
752 | |
2908 | 753 Program units ~ |
754 The indenting of program units (subroutines, functions, modules, and program | |
755 blocks) is enabled by default but can be suppressed if a lighter, screen-width | |
756 preserving indent style is desired. To suppress the indenting of program | |
757 units for all fortran files set the global fortran_indent_less variable in | |
758 your .vimrc as follows > | |
759 | |
760 let fortran_indent_less=1 | |
761 | |
762 A finer level of suppression can be achieved by setting the corresponding | |
763 buffer-local variable as follows > | |
764 | |
765 let b:fortran_indent_less=1 | |
766 | |
7 | 767 |
4869 | 768 HTML *ft-html-indent* *html-indent* *html-indenting* |
769 | |
770 This is about variables you can set in your vimrc to customize HTML indenting. | |
771 | |
772 You can set the indent for the first line after <script> and <style> | |
773 "blocktags" (default "zero"): > | |
774 | |
775 :let g:html_indent_script1 = "inc" | |
776 :let g:html_indent_style1 = "inc" | |
777 < | |
778 VALUE MEANING ~ | |
779 "zero" zero indent | |
780 "auto" auto indent (same indent as the blocktag) | |
781 "inc" auto indent + one indent step | |
782 | |
27492 | 783 You can set the indent for attributes after an open <tag line: > |
784 | |
785 :let g:html_indent_attribute = 1 | |
786 < | |
787 VALUE MEANING ~ | |
788 1 auto indent, one indent step more than <tag | |
789 2 auto indent, two indent steps (default) | |
790 > 2 auto indent, more indent steps | |
791 | |
4869 | 792 Many tags increase the indent for what follows per default (see "Add Indent |
4911 | 793 Tags" in the script). You can add further tags with: > |
4869 | 794 |
795 :let g:html_indent_inctags = "html,body,head,tbody" | |
796 | |
797 You can also remove such tags with: > | |
798 | |
799 :let g:html_indent_autotags = "th,td,tr,tfoot,thead" | |
800 | |
801 Default value is empty for both variables. Note: the initial "inctags" are | |
802 only defined once per Vim session. | |
803 | |
804 User variables are only read when the script is sourced. To enable your | |
4911 | 805 changes during a session, without reloading the HTML file, you can manually |
4869 | 806 do: > |
807 | |
808 :call HtmlIndent_CheckUserSettings() | |
809 | |
810 Detail: | |
811 Calculation of indent inside "blocktags" with "alien" content: | |
812 BLOCKTAG INDENT EXPR WHEN APPLICABLE ~ | |
4911 | 813 <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 | |
4869 | 818 <!-- --> : -1 |
819 | |
820 | |
18848 | 821 MATLAB *ft-matlab-indent* *matlab-indent* *matlab-indenting* |
822 | |
823 The setting Function indenting format in MATLAB Editor/Debugger Language | |
824 Preferences corresponds to: > | |
825 :let g:MATLAB_function_indent = {0, 1 or 2 (default)} | |
826 | |
827 Where 0 is for Classic, 1 for Indent nested functions and 2 for Indent all | |
828 functions. | |
829 | |
830 | |
1668 | 831 PHP *ft-php-indent* *php-indent* *php-indenting* |
832 | |
833 NOTE: PHP files will be indented correctly only if PHP |syntax| is active. | |
834 | |
835 If you are editing a file in Unix 'fileformat' and '\r' characters are present | |
836 before new lines, indentation won't proceed correctly ; you have to remove | |
837 those useless characters first with a command like: > | |
838 | |
839 :%s /\r$//g | |
840 | |
841 Or, you can simply |:let| the variable PHP_removeCRwhenUnix to 1 and the | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
842 script will silently remove them when Vim loads a PHP file (at each |BufRead|). |
1668 | 843 |
844 OPTIONS: ~ | |
845 | |
846 PHP indenting can be altered in several ways by modifying the values of some | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
847 global variables: |
1668 | 848 |
5862 | 849 *php-comment* *PHP_autoformatcomment* |
17667 | 850 To not enable auto-formatting of comments by default (if you want to use your |
1668 | 851 own 'formatoptions'): > |
852 :let g:PHP_autoformatcomment = 0 | |
853 | |
854 Else, 't' will be removed from the 'formatoptions' string and "qrowcb" will be | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
855 added, see |fo-table| for more information. |
1668 | 856 ------------- |
857 | |
5862 | 858 *PHP_outdentSLComments* |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
859 To add extra indentation to single-line comments: > |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
860 :let g:PHP_outdentSLComments = N |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
861 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
862 With N being the number of 'shiftwidth' to add. |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
863 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
864 Only single-line comments will be affected such as: > |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
865 # Comment |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
866 // Comment |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
867 /* Comment */ |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
868 ------------- |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
869 |
5862 | 870 *PHP_default_indenting* |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
871 To add extra indentation to every PHP lines with N being the number of |
1668 | 872 'shiftwidth' to add: > |
873 :let g:PHP_default_indenting = N | |
874 | |
875 For 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 ?> | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
887 (Notice the extra indentation between the PHP container markers and the code) |
1668 | 888 ------------- |
889 | |
5862 | 890 *PHP_outdentphpescape* |
891 To indent PHP escape tags as the surrounding non-PHP code (only affects the | |
892 PHP escape tags): > | |
27036 | 893 :let g:PHP_outdentphpescape = 0 |
2442 | 894 ------------- |
895 | |
5862 | 896 *PHP_removeCRwhenUnix* |
1668 | 897 To automatically remove '\r' characters when the 'fileformat' is set to Unix: > |
898 :let g:PHP_removeCRwhenUnix = 1 | |
899 ------------- | |
900 | |
5862 | 901 *PHP_BracesAtCodeLevel* |
1668 | 902 To indent braces at the same level than the code they contain: > |
903 :let g:PHP_BracesAtCodeLevel = 1 | |
18831 | 904 |
1668 | 905 This will give the following result: > |
906 if ($foo) | |
907 { | |
908 foo(); | |
909 } | |
910 Instead of: > | |
911 if ($foo) | |
912 { | |
913 foo(); | |
914 } | |
915 | |
916 NOTE: Indenting will be a bit slower if this option is used because some | |
917 optimizations won't be available. | |
918 ------------- | |
919 | |
17571 | 920 *PHP_vintage_case_default_indent* |
1668 | 921 To indent 'case:' and 'default:' statements in switch() blocks: > |
922 :let g:PHP_vintage_case_default_indent = 1 | |
923 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
924 In PHP braces are not required inside 'case/default' blocks therefore 'case:' |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
925 and 'default:' are indented at the same level than the 'switch()' to avoid |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
926 meaningless indentation. You can use the above option to return to the |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
927 traditional way. |
14006 | 928 ------------- |
929 | |
930 *PHP_noArrowMatching* | |
931 By default the indent script will indent multi-line chained calls by matching | |
932 the position of the '->': > | |
933 | |
934 $user_name_very_long->name() | |
935 ->age() | |
936 ->info(); | |
937 | |
938 You can revert to the classic way of indenting by setting this option to 1: > | |
939 :let g:PHP_noArrowMatching = 1 | |
940 | |
941 You will obtain the following result: > | |
942 | |
943 $user_name_very_long->name() | |
944 ->age() | |
945 ->info(); | |
946 | |
17571 | 947 ------------- |
948 | |
949 *PHP_IndentFunctionCallParameters* | |
950 Extra indentation levels to add to parameters in multi-line function calls. > | |
951 let g:PHP_IndentFunctionCallParameters = 1 | |
952 | |
953 Function 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* | |
18343 | 968 Extra indentation levels to add to arguments in multi-line function |
969 definitions. > | |
17571 | 970 let g:PHP_IndentFunctionDeclarationParameters = 1 |
971 | |
18343 | 972 Function arguments in declarations will indent 1 extra level. For two-space |
973 indentation: > | |
17571 | 974 |
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 } | |
1668 | 984 |
985 | |
501 | 986 PYTHON *ft-python-indent* |
170 | 987 |
988 The amount of indent can be set for the following situations. The examples | |
1698 | 989 given are the defaults. Note that the variables are set to an expression, so |
990 that you can change the value of 'shiftwidth' later. | |
170 | 991 |
992 Indent after an open paren: > | |
15033 | 993 let g:pyindent_open_paren = 'shiftwidth() * 2' |
170 | 994 Indent after a nested paren: > |
15033 | 995 let g:pyindent_nested_paren = 'shiftwidth()' |
170 | 996 Indent for a continuation line: > |
15033 | 997 let g:pyindent_continue = 'shiftwidth() * 2' |
170 | 998 |
21676 | 999 The method uses |searchpair()| to look back for unclosed parentheses. This |
15033 | 1000 can sometimes be slow, thus it timeouts after 150 msec. If you notice the |
14945 | 1001 indenting isn't correct, you can set a larger timeout in msec: > |
1002 let g:pyindent_searchpair_timeout = 500 | |
1003 | |
15932 | 1004 If looking back for unclosed parenthesis is still too slow, especially during |
1005 a copy-paste operation, or if you don't need indenting inside multi-line | |
1006 parentheses, you can completely disable this feature: > | |
1007 let g:pyindent_disable_parentheses_indenting = 1 | |
1008 | |
170 | 1009 |
3082 | 1010 R *ft-r-indent* |
1011 | |
1012 Function arguments are aligned if they span for multiple lines. If you prefer | |
1013 do not have the arguments of functions aligned, put in your |vimrc|: | |
1014 > | |
1015 let r_indent_align_args = 0 | |
1016 < | |
1017 All lines beginning with a comment character, #, get the same indentation | |
1018 level of the normal R code. Users of Emacs/ESS may be used to have lines | |
1019 beginning with a single # indented in the 40th column, ## indented as R code, | |
1020 and ### not indented. If you prefer that lines beginning with comment | |
1021 characters are aligned as they are by Emacs/ESS, put in your |vimrc|: | |
1022 > | |
1023 let r_indent_ess_comments = 1 | |
1024 < | |
1025 If you prefer that lines beginning with a single # are aligned at a column | |
1026 different from the 40th one, you should set a new value to the variable | |
1027 r_indent_comment_column, as in the example below: | |
1028 > | |
1029 let r_indent_comment_column = 30 | |
1030 < | |
1031 Any code after a line that ends with "<-" is indented. Emacs/ESS does not | |
1032 indent the code if it is a top level function. If you prefer that the | |
1033 Vim-R-plugin behaves like Emacs/ESS in this regard, put in your |vimrc|: | |
1034 > | |
1035 let r_indent_ess_compatible = 1 | |
1036 < | |
1037 Below 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 < | |
14637 | 1046 The code will be indented after lines that match the pattern |
1047 `'\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$'`. If you want indentation after | |
1048 lines that match a different pattern, you should set the appropriate value of | |
1049 `r_indent_op_pattern` in your |vimrc|. | |
1050 | |
3082 | 1051 |
1201 | 1052 SHELL *ft-sh-indent* |
1053 | |
1054 The amount of indent applied under various circumstances in a shell file can | |
1055 be configured by setting the following keys in the |Dictionary| | |
1056 b:sh_indent_defaults to a specific amount or to a |Funcref| that references a | |
1057 function that will return the amount desired: | |
1058 | |
1059 b:sh_indent_options['default'] Default amount of indent. | |
1060 | |
1061 b:sh_indent_options['continuation-line'] | |
1062 Amount of indent to add to a continued line. | |
1063 | |
1064 b:sh_indent_options['case-labels'] | |
1065 Amount of indent to add for case labels. | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
1066 (not actually implemented) |
1201 | 1067 |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
1068 b:sh_indent_options['case-statements'] |
1201 | 1069 Amount of indent to add for case statements. |
1070 | |
1071 b:sh_indent_options['case-breaks'] | |
1072 Amount of indent to add (or more likely | |
1073 remove) for case breaks. | |
1074 | |
501 | 1075 VERILOG *ft-verilog-indent* |
7 | 1076 |
1077 General block statements such as if, for, case, always, initial, function, | |
1078 specify and begin, etc., are indented. The module block statements (first | |
1079 level blocks) are not indented by default. you can turn on the indent with | |
1080 setting a variable in the .vimrc as follows: > | |
1081 | |
1082 let b:verilog_indent_modules = 1 | |
1083 | |
1084 then the module blocks will be indented. To stop this, remove the variable: > | |
1085 | |
1086 :unlet b:verilog_indent_modules | |
1087 | |
1088 To set the variable only for Verilog file. The following statements can be | |
1089 used: > | |
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 | |
1097 Furthermore, setting the variable b:verilog_indent_width to change the | |
1098 indenting width (default is 'shiftwidth'): > | |
1099 | |
1100 let b:verilog_indent_width = 4 | |
15033 | 1101 let b:verilog_indent_width = shiftwidth() * 2 |
7 | 1102 |
1103 In addition, you can turn the verbose mode for debug issue: > | |
1104 | |
1105 let b:verilog_indent_verbose = 1 | |
1106 | |
1107 Make sure to do ":set cmdheight=2" first to allow the display of the message. | |
1108 | |
22 | 1109 |
1620 | 1110 VHDL *ft-vhdl-indent* |
1111 | |
1112 Alignment of generic/port mapping statements are performed by default. This | |
1113 causes 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 | |
1124 To turn this off, add > | |
1125 | |
1126 let g:vhdl_indent_genportmap = 0 | |
1127 | |
1128 to 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 | |
1141 Alignment of right-hand side assignment "<=" statements are performed by | |
1142 default. 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 | |
1148 To turn this off, add > | |
1149 | |
1150 let g:vhdl_indent_rhsassign = 0 | |
1151 | |
1152 to 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 | |
1160 Full-line comments (lines that begin with "--") are indented to be aligned with | |
1161 the very previous line's comment, PROVIDED that a whitespace follows after | |
1162 "--". | |
1163 | |
1164 For example: > | |
1165 | |
1166 sig_a <= sig_b; -- start of a comment | |
1167 -- continuation of the comment | |
1168 -- more of the same comment | |
1169 | |
1170 While in Insert mode, after typing "-- " (note the space " "), hitting CTRL-F | |
1171 will align the current "-- " with the previous line's "--". | |
1172 | |
1173 If the very previous line does not contain "--", THEN the full-line comment | |
1174 will be aligned with the start of the next non-blank line that is NOT a | |
1175 full-line comment. | |
1176 | |
1177 Indenting 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 | |
1194 results 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 | |
1211 Notice that "--debug_code:" does not align with "-- comment 2" | |
1212 because there is no whitespace that follows after "--" in "--debug_code:". | |
1213 | |
1214 Given the dynamic nature of indenting comments, indenting should be done TWICE. | |
1215 On the first pass, code will be indented. On the second pass, full-line | |
1216 comments will be indented according to the correctly indented code. | |
1217 | |
1218 | |
501 | 1219 VIM *ft-vim-indent* |
27036 | 1220 *g:vim_indent_cont* |
22 | 1221 For indenting Vim scripts there is one variable that specifies the amount of |
1222 indent for a continuation line, a line that starts with a backslash: > | |
1223 | |
15033 | 1224 :let g:vim_indent_cont = shiftwidth() * 3 |
22 | 1225 |
1226 Three times shiftwidth is the default value. | |
1227 | |
1228 | |
14421 | 1229 vim:tw=78:ts=8:noet:ft=help:norl: |