codekingpro/portable-devtools
114k
1*indent.txt* For Vim version 9.2. Last change: 2026 Feb 142 3 4 VIM REFERENCE MANUAL by Bram Moolenaar5 6 7This file is about indenting C programs and other files.8 91. Indenting C style programs |C-indenting|102. Indenting by expression |indent-expression|11 12==============================================================================131. Indenting C style programs *C-indenting*14 15The basics for C style indenting are explained in section |30.2| of the user16manual.17 18Vim has options for automatically indenting C style program files. Many19programming languages including Java and C++ follow very closely the20formatting conventions established with C. These options affect only the21indent and do not perform other formatting. There are additional options that22affect other kinds of formatting as well as indenting, see |format-comments|,23|fo-table|, |gq| and |formatting| for the main ones.24 25There are in fact four main methods available for indentation, each one26overrides the previous if it is enabled, or non-empty for 'indentexpr':27'autoindent' uses the indent from the previous line.28'smartindent' is like 'autoindent' but also recognizes some C syntax to29 increase/reduce the indent where appropriate.30'cindent' Works more cleverly than the other two and is configurable to31 different indenting styles.32'indentexpr' The most flexible of all: Evaluates an expression to compute33 the indent of a line. When non-empty this method overrides34 the other ones. See |indent-expression|.35The rest of this section describes the 'cindent' option.36 37Note that 'cindent' indenting does not work for every code scenario. Vim38is not a C compiler: it does not recognize all syntax. One requirement is39that toplevel functions have a '{' in the first column. Otherwise they are40easily confused with declarations.41 42These five options control C program indenting:43'cindent' Enables Vim to perform C program indenting automatically.44'cinkeys' Specifies which keys trigger reindenting in insert mode.45'cinoptions' Sets your preferred indent style.46'cinwords' Defines keywords that start an extra indent in the next line.47'cinscopedecls' Defines strings that are recognized as a C++ scope48 declaration.49 50If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using51Vim's built-in algorithm rather than calling an external program.52 53See |autocommand| for how to set the 'cindent' option automatically for C code54files and reset it for others.55 56 *cinkeys-format* *indentkeys-format*57The 'cinkeys' option is a string that controls Vim's indenting in response to58typing certain characters or commands in certain contexts. Note that this not59only triggers C-indenting. When 'indentexpr' is not empty 'indentkeys' is60used instead. The format of 'cinkeys' and 'indentkeys' is equal.61 62The default is "0{,0},0),0],:,0#,!^F,o,O,e" which specifies that indenting63occurs as follows:64 65 "0{" if you type '{' as the first character in a line66 "0}" if you type '}' as the first character in a line67 "0)" if you type ')' as the first character in a line68 "0]" if you type ']' as the first character in a line69 ":" if you type ':' after a label or case statement70 "0#" if you type '#' as the first character in a line71 "!^F" if you type CTRL-F (which is not inserted)72 "o" if you type a <CR> anywhere or use the "o" command (not in73 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 a76 line77 78Characters that can precede each key: *i_CTRL-F*79! When a '!' precedes the key, Vim will not insert the key but will80 instead reindent the current line. This allows you to define a81 command key for reindenting the current line. CTRL-F is the default82 key for this. Be careful if you define CTRL-I for this because CTRL-I83 is the ASCII code for <Tab>.84* When a '*' precedes the key, Vim will reindent the line before85 inserting the key. If 'cinkeys' contains "*<Return>", Vim reindents86 the current line before opening a new line.870 When a zero precedes the key (but appears after '!' or '*') Vim will88 reindent the line only if the key is the first character you type in89 the line. When used before "=" Vim will only reindent the line if90 there is only white space before the word.91 92When neither '!' nor '*' precedes the key, Vim reindents the line after you93type the key. So ';' sets the indentation of a line which includes the ';'.94 95Special 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.100o Reindent a line when you use the "o" command or when Vim opens a new101 line below the current one (e.g., when you type <Enter> in insert102 mode).103O Reindent a line when you use the "O" command.104e 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 case106 statement. Don't reindent for a ":" in "class::method" for C++. To107 Reindent for any ":", use "<:>".108=word Reindent when typing the last character of "word". "word" may109 actually be part of another word. Thus "=end" would cause reindenting110 when typing the "d" in "endif" or "endwhile". But not when typing111 "bend". Also reindent when completion produces a word that starts112 with "word". "0=word" reindents when there is only white space before113 the word.114=~word Like =word, but ignore case.115 116If you really want to reindent when you type 'o', 'O', 'e', '0', '<', '>',117'*', ':' or '!', use "<o>", "<O>", "<e>", "<0>", "<<>", "<>>", "<*>", "<:>" or118"<!>", respectively, for those keys.119 120For an emacs-style indent mode where lines aren't indented every time you121press <Enter> but only if you press <Tab>, I suggest: >122 :set cinkeys=0{,0},:,0#,!<Tab>,!^F123You might also want to switch off 'autoindent' then.124 125Note: If you change the current line's indentation manually, Vim ignores the126cindent settings for that line. This prevents vim from reindenting after you127have changed the indent by typing <BS>, <Tab>, or <Space> in the indent or128used CTRL-T or CTRL-D.129 130 *cinoptions-values*131The 'cinoptions' option sets how Vim performs indentation. The value after132the option character can be one of these (N is any number):133 N indent N spaces134 -N indent N spaces to the left135 Ns N times 'shiftwidth' spaces136 -Ns N times 'shiftwidth' spaces to the left137 138In the list below,139"N" represents a number of your choice (the number can be negative). When140there 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 a142decimal point, too: "-0.5s" is minus half a 'shiftwidth'.143The examples below assume a 'shiftwidth' of 4.144 *cino->*145 >N Amount added for "normal" indent. Used after a line that should146 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<155 *cino-e*156 eN Add N to the prevailing indent inside a set of braces if the157 opening brace at the End of the line (more precise: is not the158 first character in a line). This is useful if you want a159 different indent when the '{' is at the start of the line from160 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 else167 { { {168 bar; bar; bar;169 } } }170<171 *cino-n*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 is174 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 else182 { { {183 bar; bar; bar;184 } } }185<186 *cino-f*187 fN Place the first opening brace of a function or other block in188 column N. This applies only for an opening brace that is not189 inside other braces and is at the start of the line. What comes190 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<197 *cino-{*198 {N Place opening braces N characters from the prevailing indent.199 This applies only for opening braces that are inside other200 braces. (default 0).201 202 cino= cino={.5s cino={1s >203 if (cond) if (cond) if (cond)204 { { {205 foo; foo; foo;206<207 *cino-}*208 }N Place closing braces N characters from the matching opening209 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<217 *cino-^*218 ^N Add N to the prevailing indent inside a set of braces if the219 opening brace is in column 0. This can specify a different220 indent for whole of a function (some may like to set it to a221 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<232 *cino-L*233 LN Controls placement of jump labels. If N is negative, the label234 will be placed at column 1. If N is non-negative, the indent of235 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<246 *cino-:*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<258 *cino-=*259 =N Place statements occurring after a case label N characters from260 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<266 *cino-l*267 lN If N != 0 Vim will align with a case label instead of the268 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<276 *cino-b*277 bN If N != 0 Vim will align a final "break" with the case label,278 so that case..break looks like a sort of block. (default: 0).279 When using 1, consider adding "0=break" to 'cinkeys'.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<293 *cino-g*294 gN Place C++ scope declarations N characters from the indent of the295 block they are in. (default 'shiftwidth'). By default, a scope296 declaration is "public:", "protected:" or "private:". This can297 be adjusted with the 'cinscopedecls' option.298 299 cino= cino=g0 >300 { {301 public: public:302 a = b; a = b;303 private: private:304 } }305<306 *cino-h*307 hN Place statements occurring after a C++ scope declaration N308 characters from the indent of the label. (default309 'shiftwidth').310 311 cino= cino=h10 >312 public: public: a = a + 1;313 a = a + 1; b = b + 1;314<315 *cino-N*316 NN Indent inside C++ namespace N characters extra compared to a317 normal block. (default 0).318 319 cino= cino=N-s >320 namespace { namespace {321 void function(); void function();322 } }323 324 namespace my namespace my325 { {326 void function(); void function();327 } }328<329 *cino-E*330 EN Indent inside C++ linkage specifications (extern "C" or331 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<344 *cino-p*345 pN Parameter declarations for K&R-style function declarations will346 be indented N characters from the margin. (default347 '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<354 *cino-t*355 tN Indent a function return type declaration N characters from the356 margin. (default 'shiftwidth').357 358 cino= cino=t0 cino=t7 >359 int int int360 func() func() func()361<362 *cino-i*363 iN Indent C++ base class declarations and constructor364 initializations, if they start in a new line (otherwise they365 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 BaseClass371 {} {}372 MyClass::MyClass() : MyClass::MyClass() :373 BaseClass(3) BaseClass(3)374 {} {}375<376 *cino-+*377 +N Indent a continuation line (a line that spills onto the next)378 inside a function N additional characters. (default379 'shiftwidth').380 Outside of a function, when the previous line ended in a381 backslash, the 2 * N is used.382 383 cino= cino=+10 >384 a = b + 9 * a = b + 9 *385 c; c;386<387 *cino-c*388 cN Indent comment lines after the comment opener, when there is no389 other text with which to align, N characters from the comment390 opener. (default 3). See also |format-comments|.391 392 cino= cino=c5 >393 /* /*394 text. text.395 */ */396<397 *cino-C*398 CN When N is non-zero, indent comment lines by the amount specified399 with the c flag above even if there is other text behind the400 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 408 *cino-/*409 /N Indent comment lines N characters extra. (default 0).410 cino= cino=/4 >411 a = b; a = b;412 /* comment */ /* comment */413 c = d; c = d;414<415 *cino-(*416 (N When in unclosed parentheses, indent N characters from the line417 with the unclosed parenthesis. Add a 'shiftwidth' for every418 extra unclosed parentheses. When N is 0 or the unclosed419 parenthesis is the first non-white character in its line, line420 up with the next non-white character after the unclosed421 parenthesis. (default 'shiftwidth' * 2).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<431 *cino-u*432 uN Same as (N, but for one nesting level deeper.433 (default 'shiftwidth').434 435 cino= cino=u2 >436 if (c123456789 if (c123456789437 && (c22345 && (c22345438 || c3)) || c3))439<440 *cino-U*441 UN When N is non-zero, do not ignore the indenting specified by442 ( or u in case that the unclosed parenthesis is the first443 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 c3450 ) && c4; ) && c4;451<452 *cino-w*453 wN When in unclosed parentheses and N is non-zero and either454 using "(0" or "u0", respectively, or using "U0" and the unclosed455 parenthesis is the first non-white character in its line, line456 up with the character immediately after the unclosed parenthesis457 rather than the first non-white character. (default 0).458 459 cino=(0 cino=(0,w1 >460 if ( c1 if ( c1461 && ( c2 && ( c2462 || c3)) || c3))463 foo; foo;464<465 *cino-W*466 WN When in unclosed parentheses and N is non-zero and either467 using "(0" or "u0", respectively and the unclosed parenthesis is468 the last non-white character in its line and it is not the469 closing parenthesis, indent the following line N characters470 relative to the outer context (i.e. start of the line or the471 next unclosed parenthesis). (default: 0).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<480 *cino-k*481 kN When in unclosed parentheses which follow "if", "for" or482 "while" and N is non-zero, overrides the behaviour defined by483 "(N": causes the indent to be N characters relative to the outer484 context (i.e. the line where "if", "for" or "while" is). Has485 no effect on deeper levels of nesting. Affects flags like "wN"486 only for the "if", "for" and "while" conditions. If 0, defaults487 to behaviour defined by the "(N" flag. (default: 0).488 489 cino=(0 cino=(0,ks >490 if (condition1 if (condition1491 && condition2) && condition2)492 action(); action();493 function(argument1 function(argument1494 && argument2); && argument2);495<496 *cino-m*497 mN When N is non-zero, line up a line starting with a closing498 parenthesis with the first character of the line with the499 matching opening parenthesis. (default 0).500 501 cino=(s cino=(s,m1 >502 c = c1 && ( c = c1 && (503 c2 || c2 ||504 c3 c3505 ) && c4; ) && c4;506 if ( if (507 c1 && c2 c1 && c2508 ) )509 foo; foo;510<511 *cino-M*512 MN When N is non-zero, line up a line starting with a closing513 parenthesis with the first character of the previous line.514 (default 0).515 516 cino= cino=M1 >517 if (cond1 && if (cond1 &&518 cond2 cond2519 ) )520<521 *java-cinoptions* *java-indenting* *cino-j*522 jN Indent Java anonymous classes correctly. Also works well for523 Javascript. The value 'N' is currently unused but must be524 non-zero (e.g. 'j1'). 'j1' will indent for example the525 following code snippet correctly: >526 527 object.add(new ChangeListener() {528 public void stateChanged(ChangeEvent e) {529 do_something();530 }531 });532<533 *javascript-cinoptions* *javascript-indenting* *cino-J*534 JN Indent JavaScript object declarations correctly by not confusing535 them with labels. The value 'N' is currently unused but must be536 non-zero (e.g. 'J1'). If you enable this you probably also want537 to set |cino-j|. >538 539 var bar = {540 foo: {541 that: this,542 some: ok,543 },544 "bar":{545 a : 2,546 b: "123abc",547 x: 4,548 "y": 5549 }550 }551<552 *cino-)*553 )N Vim searches for unclosed parentheses at most N lines away.554 This limits the time needed to search for parentheses. (default555 20 lines).556 557 *cino-star*558 *N Vim searches for unclosed comments at most N lines away. This559 limits the time needed to search for the start of a comment.560 If your /* */ comments stop indenting after N lines this is the561 value you will want to change.562 (default 70 lines).563 564 *cino-#*565 #N When N is non-zero recognize shell/Perl comments starting with566 '#', do not recognize preprocessor lines; allow right-shifting567 lines that start with "#".568 When N is zero (default): don't recognize '#' comments, do569 recognize preprocessor lines; right-shifting lines that start570 with "#" does not work.571 572 *cino-P*573 PN When N is non-zero recognize C pragmas, and indent them like any574 other code; does not concern other preprocessor directives.575 When N is zero (default): don't recognize C pragmas, treating576 them like every other preprocessor directive.577 578 579The defaults, spelled out in full, are:580 cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,E0,ps,ts,is,+s,581 c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0,P0582 583Vim puts a line in column 1 if:584- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'.585- It starts with a label (a keyword followed by ':', other than "case" and586 "default") and 'cinoptions' does not contain an 'L' entry with a positive587 value.588- Any combination of indentations causes the line to have less than 0589 indentation.590 591==============================================================================5922. Indenting by expression *indent-expression*593 594The basics for using flexible indenting are explained in section |30.3| of the595user manual.596 597If you want to write your own indent file, it must set the 'indentexpr'598option. Setting the 'indentkeys' option is often useful.599See the $VIMRUNTIME/indent/README.txt file for hints.600See the $VIMRUNTIME/indent directory for examples.601 602 603REMARKS ABOUT SPECIFIC INDENT FILES ~604 605 606CLOJURE *ft-clojure-indent* *clojure-indent*607 608Clojure indentation differs somewhat from traditional Lisps, due in part to609the use of square and curly brackets, and otherwise by community convention.610These conventions are not universally followed, so the Clojure indent script611offers a few configuration options.612 613(If the current Vim does not include |searchpairpos()|, the indent script falls614back to normal 'lisp' indenting, and the following options are ignored.)615 616 617 *g:clojure_maxlines*618 619Sets maximum scan distance of `searchpairpos()`. Larger values trade620performance for correctness when dealing with very long forms. A value of6210 will scan without limits. The default is 300.622 623 624 *g:clojure_fuzzy_indent*625 *g:clojure_fuzzy_indent_patterns*626 *g:clojure_fuzzy_indent_blacklist*627 628The 'lispwords' option is a list of comma-separated words that mark special629forms whose subforms should be indented with two spaces.630 631For example:632>633 (defn bad []634 "Incorrect indentation")635 636 (defn good []637 "Correct indentation")638<639If you would like to specify 'lispwords' with a |pattern| instead, you can use640the fuzzy indent feature:641>642 " Default643 let g:clojure_fuzzy_indent = 1644 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)$']647<648|g:clojure_fuzzy_indent_patterns| and |g:clojure_fuzzy_indent_blacklist| are649lists of patterns that will be matched against the unqualified symbol at the650head of a list. This means that a pattern like `"^foo"` will match all these651candidates: `foobar`, `my.ns/foobar`, and `#'foobar`.652 653Each 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 in657 |g:clojure_fuzzy_indent_blacklist|658 3. Return true if word matches a pattern in659 |g:clojure_fuzzy_indent_patterns|660 4. Return false and indent normally otherwise661 662 663 *g:clojure_special_indent_words*664 665Some forms in Clojure are indented such that every subform is indented by only666two spaces, regardless of 'lispwords'. If you have a custom construct that667should be indented in this idiosyncratic fashion, you can add your symbols to668the default list below.669>670 " Default671 let g:clojure_special_indent_words =672 \ 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'673<674 675 *g:clojure_align_multiline_strings*676 677Align subsequent lines in multi-line strings to the column after the opening678quote, instead of the same column.679 680For example:681>682 (def default683 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do684 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut685 enim ad minim veniam, quis nostrud exercitation ullamco laboris686 nisi ut aliquip ex ea commodo consequat.")687 688 (def aligned689 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do690 eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut691 enim ad minim veniam, quis nostrud exercitation ullamco laboris692 nisi ut aliquip ex ea commodo consequat.")693<694 695 *g:clojure_align_subforms*696 697By default, parenthesized compound forms that look like function calls and698whose head subform is on its own line have subsequent subforms indented by699two spaces relative to the opening paren:700>701 (foo702 bar703 baz)704<705Setting this option to `1` changes this behaviour so that all subforms are706aligned to the same column, emulating the default behaviour of707clojure-mode.el:708>709 (foo710 bar711 baz)712<713 714FORTRAN *ft-fortran-indent*715 716Block if, select case, select type, select rank, where, forall, type,717interface, associate, block, enum, critical, and change team constructs are718indented. The indenting of subroutines, functions, modules, and program719blocks is optional. Comments, labeled statements, and continuation lines are720indented in free source form, whereas they are not indented in fixed source721form because of the left margin requirements. Hence manual indent corrections722will be necessary for labeled statements and continuation lines when fixed723source form is being used. For further discussion of the method used for the724detection of source format see |ft-fortran-syntax|.725 726Do loops ~727All do loops are left unindented by default. Do loops can be unstructured in728Fortran with (possibly multiple) loops ending on a labeled executable729statement of almost arbitrary type. Correct indentation requires730compiler-quality parsing. Old code with do loops ending on labeled statements731of arbitrary type can be indented with elaborate programs such as Tidy.732Structured do/continue loops are also left unindented because continue733statements are used for purposes other than ending a do loop. Programs such734as Tidy can convert structured do/continue loops to the do/enddo form. Do735loops of the do/enddo variety can be indented. If you use only structured736loops of the do/enddo form, you should declare this by setting the737fortran_do_enddo variable in your .vimrc as follows >738 739 let fortran_do_enddo=1740 741in which case do loops will be indented. If all your loops are of do/enddo742type only in, say, .f90 files, then you should set a buffer flag with an743autocommand such as >744 745 au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1746 747to get do loops indented in .f90 files and left alone in Fortran files with748other extensions such as .for.749 750Program units ~751Indenting of program units (subroutines, functions, modules, and program752blocks) can be increased by setting the variable fortran_indent_more and can753be decreased by setting the variable fortran_indent_less. These variables754can be set for all fortran files in your .vimrc as follows >755 756 let fortran_indent_less=1757 758A finer level of control can be achieved by setting the corresponding759buffer-local variable as follows >760 761 let b:fortran_indent_less=1762 763 764HTML *ft-html-indent* *html-indent* *html-indenting*765 766This is about variables you can set in your vimrc to customize HTML indenting.767 768You can set the indent for the first line after <script> and <style>769"blocktags" (default "zero"): >770 771 :let g:html_indent_script1 = "inc"772 :let g:html_indent_style1 = "inc"773<774 VALUE MEANING ~775 "zero" zero indent776 "auto" auto indent (same indent as the blocktag)777 "inc" auto indent + one indent step778 779You can set the indent for attributes after an open <tag line: >780 781 :let g:html_indent_attribute = 1782<783 VALUE MEANING ~784 1 auto indent, one indent step more than <tag785 2 auto indent, two indent steps (default)786 > 2 auto indent, more indent steps787 788Many tags increase the indent for what follows per default (see "Add Indent789Tags" in the script). You can add further tags with: >790 791 :let g:html_indent_inctags = "html,body,head,tbody"792 793You can also remove such tags with: >794 795 :let g:html_indent_autotags = "th,td,tr,tfoot,thead"796 797Default value is empty for both variables. Note: the initial "inctags" are798only defined once per Vim session.799 800User variables are only read when the script is sourced. To enable your801changes during a session, without reloading the HTML file, you can manually802do: >803 804 :call HtmlIndent_CheckUserSettings()805 806Detail:807 Calculation of indent inside "blocktags" with "alien" content:808 BLOCKTAG INDENT EXPR WHEN APPLICABLE ~809 <script> : {customizable} if first line of block810 : cindent(v:lnum) if attributes empty or contain "java"811 : -1 else (vbscript, tcl, ...)812 <style> : {customizable} if first line of block813 : GetCSSIndent() else814 <!-- --> : -1815 816IDRIS2 *ft-idris2-indent*817 818Idris 2 indentation can be configured with several variables that control the819indentation level for different language constructs:820 821The "g:idris2_indent_if" variable controls the indentation of `then` and `else`822blocks after `if` statements. Defaults to 3.823 824The "g:idris2_indent_case" variable controls the indentation of patterns in825`case` expressions. Defaults to 5.826 827The "g:idris2_indent_let" variable controls the indentation after `let`828bindings. Defaults to 4.829 830The "g:idris2_indent_rewrite" variable controls the indentation after `rewrite`831expressions. Defaults to 8.832 833The "g:idris2_indent_where" variable controls the indentation of `where`834blocks. Defaults to 6.835 836The "g:idris2_indent_do" variable controls the indentation in `do` blocks.837Defaults to 3.838 839Example configuration: >840 841 let g:idris2_indent_if = 2842 let g:idris2_indent_case = 4843 let g:idris2_indent_let = 4844 let g:idris2_indent_rewrite = 8845 let g:idris2_indent_where = 6846 let g:idris2_indent_do = 3847<848 849MATLAB *ft-matlab-indent* *matlab-indent* *matlab-indenting*850 851The setting Function indenting format in MATLAB Editor/Debugger Language852Preferences corresponds to: >853 :let g:MATLAB_function_indent = {0, 1 or 2 (default)}854 855Where 0 is for Classic, 1 for Indent nested functions and 2 for Indent all856functions.857 858 859PHP *ft-php-indent* *php-indent* *php-indenting*860 861NOTE: PHP files will be indented correctly only if PHP |syntax| is active.862 863If you are editing a file in Unix 'fileformat' and '\r' characters are present864before new lines, indentation won't proceed correctly ; you have to remove865those useless characters first with a command like: >866 867 :%s /\r$//g868 869Or, you can simply |:let| the variable PHP_removeCRwhenUnix to 1 and the870script will silently remove them when Vim loads a PHP file (at each |BufRead|).871 872OPTIONS: ~873 874PHP indenting can be altered in several ways by modifying the values of some875global variables:876 877 *php-comment* *PHP_autoformatcomment*878To not enable auto-formatting of comments by default (if you want to use your879own 'formatoptions'): >880 :let g:PHP_autoformatcomment = 0881 882Else, 't' will be removed from the 'formatoptions' string and "qrowcb" will be883added, see |fo-table| for more information.884-------------885 886 *PHP_outdentSLComments*887To add extra indentation to single-line comments: >888 :let g:PHP_outdentSLComments = N889 890With N being the number of 'shiftwidth' to add.891 892Only single-line comments will be affected such as: >893 # Comment894 // Comment895 /* Comment */896-------------897 898 *PHP_default_indenting*899To add extra indentation to every PHP lines with N being the number of900'shiftwidth' to add: >901 :let g:PHP_default_indenting = N902 903For example, with N = 1, this will give:904>905 <?php906 if (!isset($History_lst_sel))907 if (!isset($History_lst_sel))908 if (!isset($History_lst_sel)) {909 $History_lst_sel=0;910 } else911 $foo="bar";912 913 $command_hist = TRUE;914 ?>915(Notice the extra indentation between the PHP container markers and the code)916-------------917 918 *PHP_outdentphpescape*919To indent PHP escape tags as the surrounding non-PHP code (only affects the920PHP escape tags): >921 :let g:PHP_outdentphpescape = 0922-------------923 924 *PHP_removeCRwhenUnix*925To automatically remove '\r' characters when the 'fileformat' is set to Unix: >926 :let g:PHP_removeCRwhenUnix = 1927-------------928 929 *PHP_BracesAtCodeLevel*930To indent braces at the same level than the code they contain: >931 :let g:PHP_BracesAtCodeLevel = 1932 933This will give the following result: >934 if ($foo)935 {936 foo();937 }938Instead of: >939 if ($foo)940 {941 foo();942 }943 944NOTE: Indenting will be a bit slower if this option is used because some945 optimizations won't be available.946-------------947 948 *PHP_vintage_case_default_indent*949To indent 'case:' and 'default:' statements in switch() blocks: >950 :let g:PHP_vintage_case_default_indent = 1951 952In PHP braces are not required inside 'case/default' blocks therefore 'case:'953and 'default:' are indented at the same level than the 'switch()' to avoid954meaningless indentation. You can use the above option to return to the955traditional way.956-------------957 958 *PHP_noArrowMatching*959By default the indent script will indent multi-line chained calls by matching960the position of the '->': >961 962 $user_name_very_long->name()963 ->age()964 ->info();965 966You can revert to the classic way of indenting by setting this option to 1: >967 :let g:PHP_noArrowMatching = 1968 969You will obtain the following result: >970 971 $user_name_very_long->name()972 ->age()973 ->info();974 975-------------976 977 *PHP_IndentFunctionCallParameters*978Extra indentation levels to add to parameters in multi-line function calls. >979 let g:PHP_IndentFunctionCallParameters = 1980 981Function call arguments will indent 1 extra level. For two-space indentation: >982 983 function call_the_thing(984 $with_this,985 $and_that986 ) {987 $this->do_the_thing(988 $with_this,989 $and_that990 );991 }992 993-------------994 995 *PHP_IndentFunctionDeclarationParameters*996Extra indentation levels to add to arguments in multi-line function997definitions. >998 let g:PHP_IndentFunctionDeclarationParameters = 1999 1000Function arguments in declarations will indent 1 extra level. For two-space1001indentation: >1002 1003 function call_the_thing(1004 $with_this,1005 $and_that1006 ) {1007 $this->do_the_thing(1008 $with_this,1009 $and_that1010 );1011 }1012 1013 1014PYTHON *ft-python-indent*1015 1016The amount of indent can be set with the `g:python_indent` |Dictionary|, which1017needs to be created before adding the items: >1018 let g:python_indent = {}1019The examples given are the defaults. Note that the dictionary values are set1020to an expression, so that you can change the value of 'shiftwidth' later1021without having to update these values.1022 1023Indent after an open paren: >1024 let g:python_indent.open_paren = 'shiftwidth() * 2'1025Indent after a nested paren: >1026 let g:python_indent.nested_paren = 'shiftwidth()'1027Indent for a continuation line: >1028 let g:python_indent.continue = 'shiftwidth() * 2'1029 1030By default, the closing paren on a multiline construct lines up under the1031first non-whitespace character of the previous line.1032If you prefer that it's lined up under the first character of the line that1033starts the multiline construct, reset this key: >1034 let g:python_indent.closed_paren_align_last_line = v:false1035 1036The method uses |searchpair()| to look back for unclosed parentheses. This1037can sometimes be slow, thus it timeouts after 150 msec. If you notice the1038indenting isn't correct, you can set a larger timeout in msec: >1039 let g:python_indent.searchpair_timeout = 5001040 1041If looking back for unclosed parenthesis is still too slow, especially during1042a copy-paste operation, or if you don't need indenting inside multi-line1043parentheses, you can completely disable this feature: >1044 let g:python_indent.disable_parentheses_indenting = 11045 1046For backward compatibility, these variables are also supported: >1047 g:pyindent_open_paren1048 g:pyindent_nested_paren1049 g:pyindent_continue1050 g:pyindent_searchpair_timeout1051 g:pyindent_disable_parentheses_indenting1052 1053 1054R *ft-r-indent*1055 1056Function arguments are aligned if they span for multiple lines. If you prefer1057do not have the arguments of functions aligned, put in your |vimrc|:1058>1059 let r_indent_align_args = 01060<1061All lines beginning with a comment character, #, get the same indentation1062level of the normal R code. Users of Emacs/ESS may be used to have lines1063beginning with a single # indented in the 40th column, ## indented as R code,1064and ### not indented. If you prefer that lines beginning with comment1065characters are aligned as they are by Emacs/ESS, put in your |vimrc|:1066>1067 let r_indent_ess_comments = 11068<1069If you prefer that lines beginning with a single # are aligned at a column1070different from the 40th one, you should set a new value to the variable1071r_indent_comment_column, as in the example below:1072>1073 let r_indent_comment_column = 301074<1075Any code after a line that ends with "<-" is indented. Emacs/ESS does not1076indent the code if it is a top-level function. If you prefer a behavior like1077Emacs/ESS one in this regard, put in your |vimrc|:1078>1079 let r_indent_ess_compatible = 11080<1081Below is an example of indentation with and without this option enabled:1082>1083 ### r_indent_ess_compatible = 1 ### r_indent_ess_compatible = 01084 foo <- foo <-1085 function(x) function(x)1086 { {1087 paste(x) paste(x)1088 } }1089<1090The code will be indented after lines that match the pattern1091`'\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$'`. If you want indentation after1092lines that match a different pattern, you should set the appropriate value of1093`r_indent_op_pattern` in your |vimrc|.1094 1095 1096SHELL *ft-sh-indent*1097 1098The amount of indent applied under various circumstances in a shell file can1099be configured by setting the following keys in the |Dictionary|1100b:sh_indent_defaults to a specific amount or to a |Funcref| that references a1101function that will return the amount desired:1102 1103b:sh_indent_options['default'] Default amount of indent.1104 1105b:sh_indent_options['continuation-line']1106 Amount of indent to add to a continued line.1107 1108b:sh_indent_options['case-labels']1109 Amount of indent to add for case labels.1110 (not actually implemented)1111 1112b:sh_indent_options['case-statements']1113 Amount of indent to add for case statements.1114 1115b:sh_indent_options['case-breaks']1116 Amount of indent to add (or more likely1117 remove) for case breaks.1118 1119VERILOG *ft-verilog-indent*1120 1121General block statements such as if, for, case, always, initial, function,1122specify and begin, etc., are indented. The module block statements (first1123level blocks) are not indented by default. you can turn on the indent with1124setting a variable in the .vimrc as follows: >1125 1126 let b:verilog_indent_modules = 11127 1128then the module blocks will be indented. To stop this, remove the variable: >1129 1130 :unlet b:verilog_indent_modules1131 1132To set the variable only for Verilog file. The following statements can be1133used: >1134 1135 au BufReadPost * if exists("b:current_syntax")1136 au BufReadPost * if b:current_syntax == "verilog"1137 au BufReadPost * let b:verilog_indent_modules = 11138 au BufReadPost * endif1139 au BufReadPost * endif1140 1141Furthermore, setting the variable b:verilog_indent_width to change the1142indenting width (default is 'shiftwidth'): >1143 1144 let b:verilog_indent_width = 41145 let b:verilog_indent_width = shiftwidth() * 21146 1147In addition, you can turn the verbose mode for debug issue: >1148 1149 let b:verilog_indent_verbose = 11150 1151Make sure to do ":set cmdheight=2" first to allow the display of the message.1152 1153 1154VHDL *ft-vhdl-indent*1155 1156Alignment of generic/port mapping statements are performed by default. This1157causes the following alignment example: >1158 1159 ENTITY sync IS1160 PORT (1161 clk : IN STD_LOGIC;1162 reset_n : IN STD_LOGIC;1163 data_input : IN STD_LOGIC;1164 data_out : OUT STD_LOGIC1165 );1166 END ENTITY sync;1167 1168To turn this off, add >1169 1170 let g:vhdl_indent_genportmap = 01171 1172to the .vimrc file, which causes the previous alignment example to change: >1173 1174 ENTITY sync IS1175 PORT (1176 clk : IN STD_LOGIC;1177 reset_n : IN STD_LOGIC;1178 data_input : IN STD_LOGIC;1179 data_out : OUT STD_LOGIC1180 );1181 END ENTITY sync;1182 1183----------------------------------------1184 1185Alignment of right-hand side assignment "<=" statements are performed by1186default. This causes the following alignment example: >1187 1188 sig_out <= (bus_a(1) AND1189 (sig_b OR sig_c)) OR1190 (bus_a(0) AND sig_d);1191 1192To turn this off, add >1193 1194 let g:vhdl_indent_rhsassign = 01195 1196to the .vimrc file, which causes the previous alignment example to change: >1197 1198 sig_out <= (bus_a(1) AND1199 (sig_b OR sig_c)) OR1200 (bus_a(0) AND sig_d);