blob: 8e5b7a397251b69802f02c6c57677e531fd992ab [file] [log] [blame]
Bram Moolenaar3577c6f2008-06-24 21:16:56 +00001*indent.txt* For Vim version 7.2a. Last change: 2008 Jun 21
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7This file is about indenting C programs and other files.
8
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000091. Indenting C style programs |C-indenting|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102. Indenting by expression |indent-expression|
11
12==============================================================================
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000131. Indenting C style programs *C-indenting*
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000015The basics for C style indenting are explained in section |30.2| of the user
16manual.
Bram Moolenaar071d4272004-06-13 20:20:40 +000017
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000018Vim has options for automatically indenting C style program files. Many
19programming languages including Java and C++ follow very closely the
20formatting conventions established with C. These options affect only the
21indent and do not perform other formatting. There are additional options that
22affect other kinds of formatting as well as indenting, see |format-comments|,
23|fo-table|, |gq| and |formatting| for the main ones.
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
25Note that this will not work when the |+smartindent| or |+cindent| features
26have been disabled at compile time.
27
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000028There are in fact four main methods available for indentation, each one
29overrides the previous if it is enabled, or non-empty for 'indentexpr':
Bram Moolenaar071d4272004-06-13 20:20:40 +000030'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|.
38The rest of this section describes the 'cindent' option.
39
40Note that 'cindent' indenting does not work for every code scenario. Vim
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +000041is not a C compiler: it does not recognize all syntax. One requirement is
42that toplevel functions have a '{' in the first column. Otherwise they are
43easily confused with declarations.
Bram Moolenaar071d4272004-06-13 20:20:40 +000044
45These 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
51If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
52Vim's built-in algorithm rather than calling an external program.
53
54See |autocommand| for how to set the 'cindent' option automatically for C code
55files and reset it for others.
56
57 *cinkeys-format* *indentkeys-format*
58The 'cinkeys' option is a string that controls Vim's indenting in response to
59typing certain characters or commands in certain contexts. Note that this not
60only triggers C-indenting. When 'indentexpr' is not empty 'indentkeys' is
61used instead. The format of 'cinkeys' and 'indentkeys' is equal.
62
63The default is "0{,0},0),:,0#,!^F,o,O,e" which specifies that indenting occurs
64as 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 Moolenaare2f98b92006-03-29 21:18:24 +000078Characters that can precede each key: *i_CTRL-F*
Bram Moolenaar071d4272004-06-13 20:20:40 +000079! 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.
870 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
92When neither '!' nor '*' precedes the key, Vim reindents the line after you
93type 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 new
101 line below the current one (e.g., when you type <Enter> in insert
102 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 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
116If 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
120For an emacs-style indent mode where lines aren't indented every time you
Bram Moolenaar5c3e56a2007-05-12 13:43:14 +0000121press <Enter> but only if you press <Tab>, I suggest:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122 :set cinkeys=0{,0},:,0#,!<Tab>,!^F
123You might also want to switch off 'autoindent' then.
124
125Note: If you change the current line's indentation manually, Vim ignores the
126cindent settings for that line. This prevents vim from reindenting after you
127have changed the indent by typing <BS>, <Tab>, or <Space> in the indent or
128used CTRL-T or CTRL-D.
129
130 *cinoptions-values*
131The 'cinoptions' option sets how Vim performs indentation. In the list below,
132"N" represents a number of your choice (the number can be negative). When
133there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
134"1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc. You can use a
135decimal point, too: "-0.5s" is minus half a 'shiftwidth'. The examples below
136assume a 'shiftwidth' of 4.
137
138 >N Amount added for "normal" indent. Used after a line that should
139 increase the indent (lines starting with "if", an opening brace,
140 etc.). (default 'shiftwidth').
141
142 cino= cino=>2 cino=>2s >
143 if (cond) if (cond) if (cond)
144 { { {
145 foo; foo; foo;
146 } } }
147<
148 eN Add N to the prevailing indent inside a set of braces if the
149 opening brace at the End of the line (more precise: is not the
150 first character in a line). This is useful if you want a
151 different indent when the '{' is at the start of the line from
152 when '{' is at the end of the line. (default 0).
153
154 cino= cino=e2 cino=e-2 >
155 if (cond) { if (cond) { if (cond) {
156 foo; foo; foo;
157 } } }
158 else else else
159 { { {
160 bar; bar; bar;
161 } } }
162<
163 nN Add N to the prevailing indent for a statement after an "if",
164 "while", etc., if it is NOT inside a set of braces. This is
165 useful if you want a different indent when there is no '{'
166 before the statement from when there is a '{' before it.
167 (default 0).
168
169 cino= cino=n2 cino=n-2 >
170 if (cond) if (cond) if (cond)
171 foo; foo; foo;
172 else else else
173 { { {
174 bar; bar; bar;
175 } } }
176<
177 fN Place the first opening brace of a function or other block in
178 column N. This applies only for an opening brace that is not
179 inside other braces and is at the start of the line. What comes
180 after the brace is put relative to this brace. (default 0).
181
182 cino= cino=f.5s cino=f1s >
183 func() func() func()
184 { { {
185 int foo; int foo; int foo;
186<
187 {N Place opening braces N characters from the prevailing indent.
188 This applies only for opening braces that are inside other
189 braces. (default 0).
190
191 cino= cino={.5s cino={1s >
192 if (cond) if (cond) if (cond)
193 { { {
194 foo; foo; foo;
195<
196 }N Place closing braces N characters from the matching opening
197 brace. (default 0).
198
199 cino= cino={2,}-0.5s cino=}2 >
200 if (cond) if (cond) if (cond)
201 { { {
202 foo; foo; foo;
203 } } }
204<
205 ^N Add N to the prevailing indent inside a set of braces if the
206 opening brace is in column 0. This can specify a different
207 indent for whole of a function (some may like to set it to a
208 negative number). (default 0).
209
210 cino= cino=^-2 cino=^-s >
211 func() func() func()
212 { { {
213 if (cond) if (cond) if (cond)
214 { { {
215 a = b; a = b; a = b;
216 } } }
217 } } }
218<
219 :N Place case labels N characters from the indent of the switch().
220 (default 'shiftwidth').
221
222 cino= cino=:0 >
223 switch (x) switch(x)
224 { {
225 case 1: case 1:
226 a = b; a = b;
227 default: default:
228 } }
229<
230 =N Place statements occurring after a case label N characters from
231 the indent of the label. (default 'shiftwidth').
232
233 cino= cino==10 >
234 case 11: case 11: a = a + 1;
235 a = a + 1; b = b + 1;
236<
237 lN If N != 0 Vim will align with a case label instead of the
238 statement after it in the same line.
239
240 cino= cino=l1 >
241 switch (a) { switch (a) {
242 case 1: { case 1: {
243 break; break;
244 } }
245<
246 bN If N != 0 Vim will align a final "break" with the case label,
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000247 so that case..break looks like a sort of block. (default: 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248
249 cino= cino=b1 >
250 switch (x) switch(x)
251 { {
252 case 1: case 1:
253 a = b; a = b;
254 break; break;
255
256 default: default:
257 a = 0; a = 0;
258 break; break;
259 } }
260<
261 gN Place C++ scope declarations N characters from the indent of the
262 block they are in. (default 'shiftwidth'). A scope declaration
263 can be "public:", "protected:" or "private:".
264
265 cino= cino=g0 >
266 { {
267 public: public:
268 a = b; a = b;
269 private: private:
270 } }
271<
272 hN Place statements occurring after a C++ scope declaration N
273 characters from the indent of the label. (default
274 'shiftwidth').
275
276 cino= cino=h10 >
277 public: public: a = a + 1;
278 a = a + 1; b = b + 1;
279<
280 pN Parameter declarations for K&R-style function declarations will
281 be indented N characters from the margin. (default
282 'shiftwidth').
283
284 cino= cino=p0 cino=p2s >
285 func(a, b) func(a, b) func(a, b)
286 int a; int a; int a;
287 char b; char b; char b;
288<
289 tN Indent a function return type declaration N characters from the
290 margin. (default 'shiftwidth').
291
292 cino= cino=t0 cino=t7 >
293 int int int
294 func() func() func()
295<
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000296 iN Indent C++ base class declarations and constructor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000297 initializations, if they start in a new line (otherwise they
298 are aligned at the right side of the ':').
299 (default 'shiftwidth').
300
301 cino= cino=i0 >
302 class MyClass : class MyClass :
303 public BaseClass public BaseClass
304 {} {}
305 MyClass::MyClass() : MyClass::MyClass() :
306 BaseClass(3) BaseClass(3)
307 {} {}
308<
309 +N Indent a continuation line (a line that spills onto the next) N
310 additional characters. (default 'shiftwidth').
311
312 cino= cino=+10 >
313 a = b + 9 * a = b + 9 *
314 c; c;
315<
316 cN Indent comment lines after the comment opener, when there is no
317 other text with which to align, N characters from the comment
318 opener. (default 3). See also |format-comments|.
319
320 cino= cino=c5 >
321 /* /*
322 text. text.
323 */ */
324<
325 CN When N is non-zero, indent comment lines by the amount specified
326 with the c flag above even if there is other text behind the
327 comment opener. (default 0).
328
329 cino=c0 cino=c0,C1 >
330 /******** /********
331 text. text.
332 ********/ ********/
333< (Example uses ":set comments& comments-=s1:/* comments^=s0:/*")
334
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000335 /N Indent comment lines N characters extra. (default 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000336 cino= cino=/4 >
337 a = b; a = b;
338 /* comment */ /* comment */
339 c = d; c = d;
340<
341 (N When in unclosed parentheses, indent N characters from the line
342 with the unclosed parentheses. Add a 'shiftwidth' for every
343 unclosed parentheses. When N is 0 or the unclosed parentheses
344 is the first non-white character in its line, line up with the
345 next non-white character after the unclosed parentheses.
346 (default 'shiftwidth' * 2).
347
348 cino= cino=(0 >
349 if (c1 && (c2 || if (c1 && (c2 ||
350 c3)) c3))
351 foo; foo;
352 if (c1 && if (c1 &&
353 (c2 || c3)) (c2 || c3))
354 { {
355<
356 uN Same as (N, but for one level deeper. (default 'shiftwidth').
357
358 cino= cino=u2 >
359 if (c123456789 if (c123456789
360 && (c22345 && (c22345
361 || c3)) || c3))
362<
363 UN When N is non-zero, do not ignore the indenting specified by
364 ( or u in case that the unclosed parentheses is the first
365 non-white character in its line. (default 0).
366
367 cino= or cino=(s cino=(s,U1 >
368 c = c1 && c = c1 &&
369 ( (
370 c2 || c2 ||
371 c3 c3
372 ) && c4; ) && c4;
373<
374 wN When in unclosed parentheses and N is non-zero and either
375 using "(0" or "u0", respectively, or using "U0" and the unclosed
376 parentheses is the first non-white character in its line, line
377 up with the character immediately after the unclosed parentheses
378 rather than the first non-white character. (default 0).
379
380 cino=(0 cino=(0,w1 >
381 if ( c1 if ( c1
382 && ( c2 && ( c2
383 || c3)) || c3))
384 foo; foo;
385<
386 WN When in unclosed parentheses and N is non-zero and either
387 using "(0" or "u0", respectively and the unclosed parentheses is
388 the last non-white character in its line and it is not the
389 closing parentheses, indent the following line N characters
390 relative to the outer context (i.e. start of the line or the
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000391 next unclosed parentheses). (default: 0).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392
393 cino=(0 cino=(0,W4 >
394 a_long_line( a_long_line(
395 argument, argument,
396 argument); argument);
397 a_short_line(argument, a_short_line(argument,
398 argument); argument);
399<
400 mN When N is non-zero, line up a line starting with a closing
401 parentheses with the first character of the line with the
402 matching opening parentheses. (default 0).
403
404 cino=(s cino=(s,m1 >
405 c = c1 && ( c = c1 && (
406 c2 || c2 ||
407 c3 c3
408 ) && c4; ) && c4;
409 if ( if (
410 c1 && c2 c1 && c2
411 ) )
412 foo; foo;
413<
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000414 MN When N is non-zero, line up a line starting with a closing
415 parentheses with the first character of the previous line.
416 (default 0).
417
418 cino= cino=M1 >
419 if (cond1 && if (cond1 &&
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000420 cond2 cond2
421 ) )
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000422<
Bram Moolenaar071d4272004-06-13 20:20:40 +0000423 *java-cinoptions* *java-indenting*
424 jN Indent java anonymous classes correctly. The value 'N' is
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000425 currently unused but must be non-zero (e.g. 'j1'). 'j1' will
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426 indent for example the following code snippet correctly: >
427
428 object.add(new ChangeListener() {
429 public void stateChanged(ChangeEvent e) {
430 do_something();
431 }
432 });
433<
434 )N Vim searches for unclosed parentheses at most N lines away.
435 This limits the time needed to search for parentheses. (default
436 20 lines).
437
438 *N Vim searches for unclosed comments at most N lines away. This
439 limits the time needed to search for the start of a comment.
440 (default 30 lines).
441
Bram Moolenaar39353fd2007-03-27 09:02:11 +0000442 #N When N is non-zero recognize shell/Perl comments, starting with
443 '#'. Default N is zero: don't recognizes '#' comments. Note
444 that lines starting with # will still be seen as preprocessor
445 lines.
446
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
448The defaults, spelled out in full, are:
Bram Moolenaar8299df92004-07-10 09:47:34 +0000449 cinoptions=>s,e0,n0,f0,{0,}0,^0,:s,=s,l0,b0,gs,hs,ps,ts,is,+s,c3,C0,
Bram Moolenaar39353fd2007-03-27 09:02:11 +0000450 /0,(2s,us,U0,w0,W0,m0,j0,)20,*30,#0
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
452Vim puts a line in column 1 if:
453- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#'.
454- It starts with a label (a keyword followed by ':', other than "case" and
455 "default").
456- Any combination of indentations causes the line to have less than 0
457 indentation.
458
459==============================================================================
4602. Indenting by expression *indent-expression*
461
462The basics for using flexible indenting are explained in section |30.3| of the
463user manual.
464
465If you want to write your own indent file, it must set the 'indentexpr'
466option. Setting the 'indentkeys' option is often useful. See the
467$VIMRUNTIME/indent directory for examples.
468
469
470REMARKS ABOUT SPECIFIC INDENT FILES ~
471
472
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000473FORTRAN *ft-fortran-indent*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000474
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000475Block if, select case, and where constructs are indented. Comments, labelled
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476statements and continuation lines are indented if the Fortran is in free
477source form, whereas they are not indented if the Fortran is in fixed source
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000478form because of the left margin requirements. Hence manual indent corrections
Bram Moolenaar071d4272004-06-13 20:20:40 +0000479will be necessary for labelled statements and continuation lines when fixed
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000480source form is being used. For further discussion of the method used for the
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000481detection of source format see |ft-fortran-syntax|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482
483Do loops ~
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000484All do loops are left unindented by default. Do loops can be unstructured in
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485Fortran with (possibly multiple) loops ending on a labelled executable
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000486statement of almost arbitrary type. Correct indentation requires
487compiler-quality parsing. Old code with do loops ending on labelled statements
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488of arbitrary type can be indented with elaborate programs such as Tidy
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000489(http://www.unb.ca/chem/ajit/f_tidy.htm). Structured do/continue loops are
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490also left unindented because continue statements are also used for purposes
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000491other than ending a do loop. Programs such as Tidy can convert structured
492do/continue loops to the do/enddo form. Do loops of the do/enddo variety can
493be indented. If you use only structured loops of the do/enddo form, you should
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494declare this by setting the fortran_do_enddo variable in your .vimrc as
495follows >
496
497 let fortran_do_enddo=1
498
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000499in which case do loops will be indented. If all your loops are of do/enddo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500type only in, say, .f90 files, then you should set a buffer flag with an
501autocommand such as >
502
503 au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1
504
505to get do loops indented in .f90 files and left alone in Fortran files with
506other extensions such as .for.
507
508
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000509PYTHON *ft-python-indent*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000510
511The amount of indent can be set for the following situations. The examples
512given are de the defaults. Note that the variables are set to an expression,
513so that you can change the value of 'shiftwidth' later.
514
515Indent after an open paren: >
516 let g:pyindent_open_paren = '&sw * 2'
517Indent after a nested paren: >
518 let g:pyindent_nested_paren = '&sw'
519Indent for a continuation line: >
520 let g:pyindent_continue = '&sw * 2'
521
522
Bram Moolenaar7263a772007-05-10 17:35:54 +0000523SHELL *ft-sh-indent*
524
525The amount of indent applied under various circumstances in a shell file can
526be configured by setting the following keys in the |Dictionary|
527b:sh_indent_defaults to a specific amount or to a |Funcref| that references a
528function that will return the amount desired:
529
530b:sh_indent_options['default'] Default amount of indent.
531
532b:sh_indent_options['continuation-line']
533 Amount of indent to add to a continued line.
534
535b:sh_indent_options['case-labels']
536 Amount of indent to add for case labels.
537
538b:sh_indent_options['case-statement']
539 Amount of indent to add for case statements.
540
541b:sh_indent_options['case-breaks']
542 Amount of indent to add (or more likely
543 remove) for case breaks.
544
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000545VERILOG *ft-verilog-indent*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546
547General block statements such as if, for, case, always, initial, function,
548specify and begin, etc., are indented. The module block statements (first
549level blocks) are not indented by default. you can turn on the indent with
550setting a variable in the .vimrc as follows: >
551
552 let b:verilog_indent_modules = 1
553
554then the module blocks will be indented. To stop this, remove the variable: >
555
556 :unlet b:verilog_indent_modules
557
558To set the variable only for Verilog file. The following statements can be
559used: >
560
561 au BufReadPost * if exists("b:current_syntax")
562 au BufReadPost * if b:current_syntax == "verilog"
563 au BufReadPost * let b:verilog_indent_modules = 1
564 au BufReadPost * endif
565 au BufReadPost * endif
566
567Furthermore, setting the variable b:verilog_indent_width to change the
568indenting width (default is 'shiftwidth'): >
569
570 let b:verilog_indent_width = 4
571 let b:verilog_indent_width = &sw * 2
572
573In addition, you can turn the verbose mode for debug issue: >
574
575 let b:verilog_indent_verbose = 1
576
577Make sure to do ":set cmdheight=2" first to allow the display of the message.
578
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000579
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000580VHDL *ft-vhdl-indent*
581
582Alignment of generic/port mapping statements are performed by default. This
583causes the following alignment example: >
584
585 ENTITY sync IS
586 PORT (
587 clk : IN STD_LOGIC;
588 reset_n : IN STD_LOGIC;
589 data_input : IN STD_LOGIC;
590 data_out : OUT STD_LOGIC
591 );
592 END ENTITY sync;
593
594To turn this off, add >
595
596 let g:vhdl_indent_genportmap = 0
597
598to the .vimrc file, which causes the previous alignment example to change: >
599
600 ENTITY sync IS
601 PORT (
602 clk : IN STD_LOGIC;
603 reset_n : IN STD_LOGIC;
604 data_input : IN STD_LOGIC;
605 data_out : OUT STD_LOGIC
606 );
607 END ENTITY sync;
608
609----------------------------------------
610
611Alignment of right-hand side assignment "<=" statements are performed by
612default. This causes the following alignment example: >
613
614 sig_out <= (bus_a(1) AND
615 (sig_b OR sig_c)) OR
616 (bus_a(0) AND sig_d);
617
618To turn this off, add >
619
620 let g:vhdl_indent_rhsassign = 0
621
622to the .vimrc file, which causes the previous alignment example to change: >
623
624 sig_out <= (bus_a(1) AND
625 (sig_b OR sig_c)) OR
626 (bus_a(0) AND sig_d);
627
628----------------------------------------
629
630Full-line comments (lines that begin with "--") are indented to be aligned with
631the very previous line's comment, PROVIDED that a whitespace follows after
632"--".
633
634For example: >
635
636 sig_a <= sig_b; -- start of a comment
637 -- continuation of the comment
638 -- more of the same comment
639
640While in Insert mode, after typing "-- " (note the space " "), hitting CTRL-F
641will align the current "-- " with the previous line's "--".
642
643If the very previous line does not contain "--", THEN the full-line comment
644will be aligned with the start of the next non-blank line that is NOT a
645full-line comment.
646
647Indenting the following code: >
648
649 sig_c <= sig_d; -- comment 0
650 -- comment 1
651 -- comment 2
652 --debug_code:
653 --PROCESS(debug_in)
654 --BEGIN
655 -- FOR i IN 15 DOWNTO 0 LOOP
656 -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i);
657 -- END LOOP;
658 --END PROCESS debug_code;
659
660 -- comment 3
661 sig_e <= sig_f; -- comment 4
662 -- comment 5
663
664results in: >
665
666 sig_c <= sig_d; -- comment 0
667 -- comment 1
668 -- comment 2
669 --debug_code:
670 --PROCESS(debug_in)
671 --BEGIN
672 -- FOR i IN 15 DOWNTO 0 LOOP
673 -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i);
674 -- END LOOP;
675 --END PROCESS debug_code;
676
677 -- comment 3
678 sig_e <= sig_f; -- comment 4
679 -- comment 5
680
681Notice that "--debug_code:" does not align with "-- comment 2"
682because there is no whitespace that follows after "--" in "--debug_code:".
683
684Given the dynamic nature of indenting comments, indenting should be done TWICE.
685On the first pass, code will be indented. On the second pass, full-line
686comments will be indented according to the correctly indented code.
687
688
Bram Moolenaarda2303d2005-08-30 21:55:26 +0000689VIM *ft-vim-indent*
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000690
691For indenting Vim scripts there is one variable that specifies the amount of
692indent for a continuation line, a line that starts with a backslash: >
693
694 :let g:vim_indent_cont = &sw * 3
695
696Three times shiftwidth is the default value.
697
698
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699 vim:tw=78:ts=8:ft=help:norl: