Bram Moolenaar | 8e5af3e | 2011-04-28 19:02:44 +0200 | [diff] [blame] | 1 | *indent.txt* For Vim version 7.3. Last change: 2011 Apr 25 |
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 |
| 135 | Ns N times 'shiftwidth spaces |
| 136 | -Ns N times 'shiftwidth spaces to the left |
| 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 | < |
| 328 | *cino-p* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 329 | pN Parameter declarations for K&R-style function declarations will |
| 330 | be indented N characters from the margin. (default |
| 331 | 'shiftwidth'). |
| 332 | |
| 333 | cino= cino=p0 cino=p2s > |
| 334 | func(a, b) func(a, b) func(a, b) |
| 335 | int a; int a; int a; |
| 336 | char b; char b; char b; |
| 337 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 338 | *cino-t* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 339 | tN Indent a function return type declaration N characters from the |
| 340 | margin. (default 'shiftwidth'). |
| 341 | |
| 342 | cino= cino=t0 cino=t7 > |
| 343 | int int int |
| 344 | func() func() func() |
| 345 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 346 | *cino-i* |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 347 | iN Indent C++ base class declarations and constructor |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 348 | initializations, if they start in a new line (otherwise they |
| 349 | are aligned at the right side of the ':'). |
| 350 | (default 'shiftwidth'). |
| 351 | |
| 352 | cino= cino=i0 > |
| 353 | class MyClass : class MyClass : |
| 354 | public BaseClass public BaseClass |
| 355 | {} {} |
| 356 | MyClass::MyClass() : MyClass::MyClass() : |
| 357 | BaseClass(3) BaseClass(3) |
| 358 | {} {} |
| 359 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 360 | *cino-+* |
Bram Moolenaar | 662db67 | 2011-03-22 14:05:35 +0100 | [diff] [blame] | 361 | +N Indent a continuation line (a line that spills onto the next) |
| 362 | inside a function N additional characters. (default |
| 363 | 'shiftwidth'). |
| 364 | Outside of a function, when the previous line ended in a |
| 365 | backslash, the 2 * N is used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 366 | |
| 367 | cino= cino=+10 > |
| 368 | a = b + 9 * a = b + 9 * |
| 369 | c; c; |
| 370 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 371 | *cino-c* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 372 | cN Indent comment lines after the comment opener, when there is no |
| 373 | other text with which to align, N characters from the comment |
| 374 | opener. (default 3). See also |format-comments|. |
| 375 | |
| 376 | cino= cino=c5 > |
| 377 | /* /* |
| 378 | text. text. |
| 379 | */ */ |
| 380 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 381 | *cino-C* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 382 | CN When N is non-zero, indent comment lines by the amount specified |
| 383 | with the c flag above even if there is other text behind the |
| 384 | comment opener. (default 0). |
| 385 | |
| 386 | cino=c0 cino=c0,C1 > |
| 387 | /******** /******** |
| 388 | text. text. |
| 389 | ********/ ********/ |
| 390 | < (Example uses ":set comments& comments-=s1:/* comments^=s0:/*") |
| 391 | |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 392 | *cino-/* |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 393 | /N Indent comment lines N characters extra. (default 0). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 394 | cino= cino=/4 > |
| 395 | a = b; a = b; |
| 396 | /* comment */ /* comment */ |
| 397 | c = d; c = d; |
| 398 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 399 | *cino-(* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 400 | (N When in unclosed parentheses, indent N characters from the line |
| 401 | with the unclosed parentheses. Add a 'shiftwidth' for every |
| 402 | unclosed parentheses. When N is 0 or the unclosed parentheses |
| 403 | is the first non-white character in its line, line up with the |
| 404 | next non-white character after the unclosed parentheses. |
| 405 | (default 'shiftwidth' * 2). |
| 406 | |
| 407 | cino= cino=(0 > |
| 408 | if (c1 && (c2 || if (c1 && (c2 || |
| 409 | c3)) c3)) |
| 410 | foo; foo; |
| 411 | if (c1 && if (c1 && |
| 412 | (c2 || c3)) (c2 || c3)) |
| 413 | { { |
| 414 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 415 | *cino-u* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 416 | uN Same as (N, but for one level deeper. (default 'shiftwidth'). |
| 417 | |
| 418 | cino= cino=u2 > |
| 419 | if (c123456789 if (c123456789 |
| 420 | && (c22345 && (c22345 |
| 421 | || c3)) || c3)) |
| 422 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 423 | *cino-U* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 424 | UN When N is non-zero, do not ignore the indenting specified by |
| 425 | ( or u in case that the unclosed parentheses is the first |
| 426 | non-white character in its line. (default 0). |
| 427 | |
| 428 | cino= or cino=(s cino=(s,U1 > |
| 429 | c = c1 && c = c1 && |
| 430 | ( ( |
| 431 | c2 || c2 || |
| 432 | c3 c3 |
| 433 | ) && c4; ) && c4; |
| 434 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 435 | *cino-2* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 436 | wN When in unclosed parentheses and N is non-zero and either |
| 437 | using "(0" or "u0", respectively, or using "U0" and the unclosed |
| 438 | parentheses is the first non-white character in its line, line |
| 439 | up with the character immediately after the unclosed parentheses |
| 440 | rather than the first non-white character. (default 0). |
| 441 | |
| 442 | cino=(0 cino=(0,w1 > |
| 443 | if ( c1 if ( c1 |
| 444 | && ( c2 && ( c2 |
| 445 | || c3)) || c3)) |
| 446 | foo; foo; |
| 447 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 448 | *cino-W* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 449 | WN When in unclosed parentheses and N is non-zero and either |
| 450 | using "(0" or "u0", respectively and the unclosed parentheses is |
| 451 | the last non-white character in its line and it is not the |
| 452 | closing parentheses, indent the following line N characters |
| 453 | 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] | 454 | next unclosed parentheses). (default: 0). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 455 | |
| 456 | cino=(0 cino=(0,W4 > |
| 457 | a_long_line( a_long_line( |
| 458 | argument, argument, |
| 459 | argument); argument); |
| 460 | a_short_line(argument, a_short_line(argument, |
| 461 | argument); argument); |
| 462 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 463 | *cino-m* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 464 | mN When N is non-zero, line up a line starting with a closing |
| 465 | parentheses with the first character of the line with the |
| 466 | matching opening parentheses. (default 0). |
| 467 | |
| 468 | cino=(s cino=(s,m1 > |
| 469 | c = c1 && ( c = c1 && ( |
| 470 | c2 || c2 || |
| 471 | c3 c3 |
| 472 | ) && c4; ) && c4; |
| 473 | if ( if ( |
| 474 | c1 && c2 c1 && c2 |
| 475 | ) ) |
| 476 | foo; foo; |
| 477 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 478 | *cino-M* |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 479 | MN When N is non-zero, line up a line starting with a closing |
| 480 | parentheses with the first character of the previous line. |
| 481 | (default 0). |
| 482 | |
| 483 | cino= cino=M1 > |
| 484 | if (cond1 && if (cond1 && |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 485 | cond2 cond2 |
| 486 | ) ) |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 487 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 488 | *java-cinoptions* *java-indenting* *cino-j* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 489 | jN Indent java anonymous classes correctly. The value 'N' is |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 490 | currently unused but must be non-zero (e.g. 'j1'). 'j1' will |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 491 | indent for example the following code snippet correctly: > |
| 492 | |
| 493 | object.add(new ChangeListener() { |
| 494 | public void stateChanged(ChangeEvent e) { |
| 495 | do_something(); |
| 496 | } |
| 497 | }); |
| 498 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 499 | *javascript-cinoptions* *javascript-indenting* *cino-J* |
Bram Moolenaar | 3acfc30 | 2010-07-11 17:23:02 +0200 | [diff] [blame] | 500 | JN Indent JavaScript object declarations correctly by not confusing |
| 501 | them with labels. The value 'N' is currently unused but must be |
| 502 | non-zero (e.g. 'J1'). > |
| 503 | |
| 504 | var bar = { |
| 505 | foo: { |
| 506 | that: this, |
| 507 | some: ok, |
| 508 | }, |
| 509 | "bar":{ |
| 510 | a : 2, |
| 511 | b: "123abc", |
| 512 | x: 4, |
| 513 | "y": 5 |
| 514 | } |
| 515 | } |
| 516 | < |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 517 | *cino-)* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 518 | )N Vim searches for unclosed parentheses at most N lines away. |
| 519 | This limits the time needed to search for parentheses. (default |
| 520 | 20 lines). |
| 521 | |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 522 | *cino-star* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 523 | *N Vim searches for unclosed comments at most N lines away. This |
| 524 | limits the time needed to search for the start of a comment. |
Bram Moolenaar | 8e5af3e | 2011-04-28 19:02:44 +0200 | [diff] [blame] | 525 | If your /* */ comments stop indenting afer N lines this is the |
| 526 | value you will want to change. |
Bram Moolenaar | 6dfc28b | 2010-02-11 14:19:15 +0100 | [diff] [blame] | 527 | (default 70 lines). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 528 | |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 529 | *cino-#* |
Bram Moolenaar | 39353fd | 2007-03-27 09:02:11 +0000 | [diff] [blame] | 530 | #N When N is non-zero recognize shell/Perl comments, starting with |
| 531 | '#'. Default N is zero: don't recognizes '#' comments. Note |
| 532 | that lines starting with # will still be seen as preprocessor |
| 533 | lines. |
| 534 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 535 | |
| 536 | The defaults, spelled out in full, are: |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame] | 537 | cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,ps,ts,is,+s, |
Bram Moolenaar | 02c707a | 2010-07-17 17:12:06 +0200 | [diff] [blame] | 538 | c3,C0,/0,(2s,us,U0,w0,W0,m0,j0,J0,)20,*70,#0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 539 | |
| 540 | Vim puts a line in column 1 if: |
| 541 | - It starts with '#' (preprocessor directives), if 'cinkeys' contains '#'. |
| 542 | - 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] | 543 | "default") and 'cinoptions' does not contain an 'L' entry with a positive |
| 544 | value. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 545 | - Any combination of indentations causes the line to have less than 0 |
| 546 | indentation. |
| 547 | |
| 548 | ============================================================================== |
| 549 | 2. Indenting by expression *indent-expression* |
| 550 | |
| 551 | The basics for using flexible indenting are explained in section |30.3| of the |
| 552 | user manual. |
| 553 | |
| 554 | If you want to write your own indent file, it must set the 'indentexpr' |
| 555 | option. Setting the 'indentkeys' option is often useful. See the |
| 556 | $VIMRUNTIME/indent directory for examples. |
| 557 | |
| 558 | |
| 559 | REMARKS ABOUT SPECIFIC INDENT FILES ~ |
| 560 | |
| 561 | |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 562 | FORTRAN *ft-fortran-indent* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 563 | |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 564 | Block if, select case, and where constructs are indented. Comments, labelled |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 565 | statements and continuation lines are indented if the Fortran is in free |
| 566 | source form, whereas they are not indented if the Fortran is in fixed source |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 567 | form because of the left margin requirements. Hence manual indent corrections |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 568 | will be necessary for labelled statements and continuation lines when fixed |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 569 | source form is being used. For further discussion of the method used for the |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 570 | detection of source format see |ft-fortran-syntax|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 571 | |
| 572 | Do loops ~ |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 573 | 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] | 574 | Fortran with (possibly multiple) loops ending on a labelled executable |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 575 | statement of almost arbitrary type. Correct indentation requires |
| 576 | compiler-quality parsing. Old code with do loops ending on labelled statements |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 577 | of arbitrary type can be indented with elaborate programs such as Tidy |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 578 | (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] | 579 | also left unindented because continue statements are also used for purposes |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 580 | other than ending a do loop. Programs such as Tidy can convert structured |
| 581 | do/continue loops to the do/enddo form. Do loops of the do/enddo variety can |
| 582 | 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] | 583 | declare this by setting the fortran_do_enddo variable in your .vimrc as |
| 584 | follows > |
| 585 | |
| 586 | let fortran_do_enddo=1 |
| 587 | |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 588 | 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] | 589 | type only in, say, .f90 files, then you should set a buffer flag with an |
| 590 | autocommand such as > |
| 591 | |
| 592 | au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1 |
| 593 | |
| 594 | to get do loops indented in .f90 files and left alone in Fortran files with |
| 595 | other extensions such as .for. |
| 596 | |
| 597 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 598 | PHP *ft-php-indent* *php-indent* *php-indenting* |
| 599 | |
| 600 | NOTE: PHP files will be indented correctly only if PHP |syntax| is active. |
| 601 | |
| 602 | If you are editing a file in Unix 'fileformat' and '\r' characters are present |
| 603 | before new lines, indentation won't proceed correctly ; you have to remove |
| 604 | those useless characters first with a command like: > |
| 605 | |
| 606 | :%s /\r$//g |
| 607 | |
| 608 | Or, you can simply |:let| the variable PHP_removeCRwhenUnix to 1 and the |
Bram Moolenaar | 8408a9a | 2010-07-30 22:41:22 +0200 | [diff] [blame] | 609 | 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] | 610 | |
| 611 | OPTIONS: ~ |
| 612 | |
| 613 | PHP indenting can be altered in several ways by modifying the values of some |
| 614 | variables: |
| 615 | |
| 616 | *php-comment* |
Bram Moolenaar | 8408a9a | 2010-07-30 22:41:22 +0200 | [diff] [blame] | 617 | To not enable auto-formating of comments by default (if you want to use your |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 618 | own 'formatoptions'): > |
| 619 | :let g:PHP_autoformatcomment = 0 |
| 620 | |
| 621 | Else, 't' will be removed from the 'formatoptions' string and "qrowcb" will be |
| 622 | added, see|fo-table|for more information. |
| 623 | ------------- |
| 624 | |
| 625 | To add an extra indent to every PHP lines with N being the number of |
| 626 | 'shiftwidth' to add: > |
| 627 | :let g:PHP_default_indenting = N |
| 628 | |
| 629 | For example, with N = 1, this will give: |
| 630 | > |
| 631 | <?php |
| 632 | if (!isset($History_lst_sel)) |
| 633 | if (!isset($History_lst_sel)) |
| 634 | if (!isset($History_lst_sel)) { |
| 635 | $History_lst_sel=0; |
| 636 | } else |
| 637 | $foo="bar"; |
| 638 | |
| 639 | $command_hist = TRUE; |
| 640 | ?> |
| 641 | (Notice the extra indent between the PHP container markers and the code) |
| 642 | ------------- |
| 643 | |
Bram Moolenaar | 8408a9a | 2010-07-30 22:41:22 +0200 | [diff] [blame] | 644 | To indent PHP tags as the surrounding code: > |
| 645 | :let g:PHP_outdentphpescape = 0 |
| 646 | ------------- |
| 647 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 648 | To automatically remove '\r' characters when the 'fileformat' is set to Unix: > |
| 649 | :let g:PHP_removeCRwhenUnix = 1 |
| 650 | ------------- |
| 651 | |
| 652 | To indent braces at the same level than the code they contain: > |
| 653 | :let g:PHP_BracesAtCodeLevel = 1 |
| 654 | |
| 655 | This will give the following result: > |
| 656 | if ($foo) |
| 657 | { |
| 658 | foo(); |
| 659 | } |
| 660 | Instead of: > |
| 661 | if ($foo) |
| 662 | { |
| 663 | foo(); |
| 664 | } |
| 665 | |
| 666 | NOTE: Indenting will be a bit slower if this option is used because some |
| 667 | optimizations won't be available. |
| 668 | ------------- |
| 669 | |
| 670 | To indent 'case:' and 'default:' statements in switch() blocks: > |
| 671 | :let g:PHP_vintage_case_default_indent = 1 |
| 672 | |
Bram Moolenaar | 8408a9a | 2010-07-30 22:41:22 +0200 | [diff] [blame] | 673 | (Since in PHP braces are not required inside 'case/default' blocks, by default they are indented at the same level than the 'switch()' to avoid |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 674 | unnecessary indentation) |
| 675 | |
| 676 | |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 677 | PYTHON *ft-python-indent* |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 678 | |
| 679 | 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] | 680 | given are the defaults. Note that the variables are set to an expression, so |
| 681 | that you can change the value of 'shiftwidth' later. |
Bram Moolenaar | 05159a0 | 2005-02-26 23:04:13 +0000 | [diff] [blame] | 682 | |
| 683 | Indent after an open paren: > |
| 684 | let g:pyindent_open_paren = '&sw * 2' |
| 685 | Indent after a nested paren: > |
| 686 | let g:pyindent_nested_paren = '&sw' |
| 687 | Indent for a continuation line: > |
| 688 | let g:pyindent_continue = '&sw * 2' |
| 689 | |
| 690 | |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 691 | SHELL *ft-sh-indent* |
| 692 | |
| 693 | The amount of indent applied under various circumstances in a shell file can |
| 694 | be configured by setting the following keys in the |Dictionary| |
| 695 | b:sh_indent_defaults to a specific amount or to a |Funcref| that references a |
| 696 | function that will return the amount desired: |
| 697 | |
| 698 | b:sh_indent_options['default'] Default amount of indent. |
| 699 | |
| 700 | b:sh_indent_options['continuation-line'] |
| 701 | Amount of indent to add to a continued line. |
| 702 | |
| 703 | b:sh_indent_options['case-labels'] |
| 704 | Amount of indent to add for case labels. |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 705 | (not actually implemented) |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 706 | |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 707 | b:sh_indent_options['case-statements'] |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 708 | Amount of indent to add for case statements. |
| 709 | |
| 710 | b:sh_indent_options['case-breaks'] |
| 711 | Amount of indent to add (or more likely |
| 712 | remove) for case breaks. |
| 713 | |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 714 | VERILOG *ft-verilog-indent* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 715 | |
| 716 | General block statements such as if, for, case, always, initial, function, |
| 717 | specify and begin, etc., are indented. The module block statements (first |
| 718 | level blocks) are not indented by default. you can turn on the indent with |
| 719 | setting a variable in the .vimrc as follows: > |
| 720 | |
| 721 | let b:verilog_indent_modules = 1 |
| 722 | |
| 723 | then the module blocks will be indented. To stop this, remove the variable: > |
| 724 | |
| 725 | :unlet b:verilog_indent_modules |
| 726 | |
| 727 | To set the variable only for Verilog file. The following statements can be |
| 728 | used: > |
| 729 | |
| 730 | au BufReadPost * if exists("b:current_syntax") |
| 731 | au BufReadPost * if b:current_syntax == "verilog" |
| 732 | au BufReadPost * let b:verilog_indent_modules = 1 |
| 733 | au BufReadPost * endif |
| 734 | au BufReadPost * endif |
| 735 | |
| 736 | Furthermore, setting the variable b:verilog_indent_width to change the |
| 737 | indenting width (default is 'shiftwidth'): > |
| 738 | |
| 739 | let b:verilog_indent_width = 4 |
| 740 | let b:verilog_indent_width = &sw * 2 |
| 741 | |
| 742 | In addition, you can turn the verbose mode for debug issue: > |
| 743 | |
| 744 | let b:verilog_indent_verbose = 1 |
| 745 | |
| 746 | Make sure to do ":set cmdheight=2" first to allow the display of the message. |
| 747 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 748 | |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 749 | VHDL *ft-vhdl-indent* |
| 750 | |
| 751 | Alignment of generic/port mapping statements are performed by default. This |
| 752 | causes the following alignment example: > |
| 753 | |
| 754 | ENTITY sync IS |
| 755 | PORT ( |
| 756 | clk : IN STD_LOGIC; |
| 757 | reset_n : IN STD_LOGIC; |
| 758 | data_input : IN STD_LOGIC; |
| 759 | data_out : OUT STD_LOGIC |
| 760 | ); |
| 761 | END ENTITY sync; |
| 762 | |
| 763 | To turn this off, add > |
| 764 | |
| 765 | let g:vhdl_indent_genportmap = 0 |
| 766 | |
| 767 | to the .vimrc file, which causes the previous alignment example to change: > |
| 768 | |
| 769 | ENTITY sync IS |
| 770 | PORT ( |
| 771 | clk : IN STD_LOGIC; |
| 772 | reset_n : IN STD_LOGIC; |
| 773 | data_input : IN STD_LOGIC; |
| 774 | data_out : OUT STD_LOGIC |
| 775 | ); |
| 776 | END ENTITY sync; |
| 777 | |
| 778 | ---------------------------------------- |
| 779 | |
| 780 | Alignment of right-hand side assignment "<=" statements are performed by |
| 781 | default. This causes the following alignment example: > |
| 782 | |
| 783 | sig_out <= (bus_a(1) AND |
| 784 | (sig_b OR sig_c)) OR |
| 785 | (bus_a(0) AND sig_d); |
| 786 | |
| 787 | To turn this off, add > |
| 788 | |
| 789 | let g:vhdl_indent_rhsassign = 0 |
| 790 | |
| 791 | to the .vimrc file, which causes the previous alignment example to change: > |
| 792 | |
| 793 | sig_out <= (bus_a(1) AND |
| 794 | (sig_b OR sig_c)) OR |
| 795 | (bus_a(0) AND sig_d); |
| 796 | |
| 797 | ---------------------------------------- |
| 798 | |
| 799 | Full-line comments (lines that begin with "--") are indented to be aligned with |
| 800 | the very previous line's comment, PROVIDED that a whitespace follows after |
| 801 | "--". |
| 802 | |
| 803 | For example: > |
| 804 | |
| 805 | sig_a <= sig_b; -- start of a comment |
| 806 | -- continuation of the comment |
| 807 | -- more of the same comment |
| 808 | |
| 809 | While in Insert mode, after typing "-- " (note the space " "), hitting CTRL-F |
| 810 | will align the current "-- " with the previous line's "--". |
| 811 | |
| 812 | If the very previous line does not contain "--", THEN the full-line comment |
| 813 | will be aligned with the start of the next non-blank line that is NOT a |
| 814 | full-line comment. |
| 815 | |
| 816 | Indenting the following code: > |
| 817 | |
| 818 | sig_c <= sig_d; -- comment 0 |
| 819 | -- comment 1 |
| 820 | -- comment 2 |
| 821 | --debug_code: |
| 822 | --PROCESS(debug_in) |
| 823 | --BEGIN |
| 824 | -- FOR i IN 15 DOWNTO 0 LOOP |
| 825 | -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i); |
| 826 | -- END LOOP; |
| 827 | --END PROCESS debug_code; |
| 828 | |
| 829 | -- comment 3 |
| 830 | sig_e <= sig_f; -- comment 4 |
| 831 | -- comment 5 |
| 832 | |
| 833 | results in: > |
| 834 | |
| 835 | sig_c <= sig_d; -- comment 0 |
| 836 | -- comment 1 |
| 837 | -- comment 2 |
| 838 | --debug_code: |
| 839 | --PROCESS(debug_in) |
| 840 | --BEGIN |
| 841 | -- FOR i IN 15 DOWNTO 0 LOOP |
| 842 | -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i); |
| 843 | -- END LOOP; |
| 844 | --END PROCESS debug_code; |
| 845 | |
| 846 | -- comment 3 |
| 847 | sig_e <= sig_f; -- comment 4 |
| 848 | -- comment 5 |
| 849 | |
| 850 | Notice that "--debug_code:" does not align with "-- comment 2" |
| 851 | because there is no whitespace that follows after "--" in "--debug_code:". |
| 852 | |
| 853 | Given the dynamic nature of indenting comments, indenting should be done TWICE. |
| 854 | On the first pass, code will be indented. On the second pass, full-line |
| 855 | comments will be indented according to the correctly indented code. |
| 856 | |
| 857 | |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 858 | VIM *ft-vim-indent* |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 859 | |
| 860 | For indenting Vim scripts there is one variable that specifies the amount of |
| 861 | indent for a continuation line, a line that starts with a backslash: > |
| 862 | |
| 863 | :let g:vim_indent_cont = &sw * 3 |
| 864 | |
| 865 | Three times shiftwidth is the default value. |
| 866 | |
| 867 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 868 | vim:tw=78:ts=8:ft=help:norl: |