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