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