indent.txt 39 KB

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