Linux indent Command
The Linux indent command is used to adjust the formatting of C source code files.
indent recognizes C source code files and formats them for easier reading by programmers.
Syntax
indent [参数][源文件] 或 indent [参数][源文件][-o 目标文件]
Parameters:
- -bad or --blank-lines-after-declarations Add blank lines after declaration sections.
- -bap or --blank-lines-after-procedures Add a blank line after procedures.
- -bbb or --blank-lines-after-block-comments Add a blank line after block comment sections.
- -bc or --blank-lines-after-commas In declaration sections, break the line whenever a comma appears.
- -bl or --braces-after-if-line Place if (or else, for, etc.) and the "{" of the following block on different lines, with "}" on its own line.
- -bli
or --brace-indent Set the number of spaces for { } indentation. - -br or --braces-on-if-line Place if (or else, for, etc.) and the "{" of the following block on different lines, with "}" on its own line.
- -bs or --blank-before-sizeof Leave a space after sizeof.
- -c
or --comment-indentation Place comments at the specified column to the right of the code. - -cd
or --declaration-comment-column Place comments at the specified column to the right of declarations. - -cdb or --comment-delimiters-on-blank-lines Put comment delimiters on their own line.
- -ce or --cuddle-else Place else after "}" (the end of the if block).
- -ci
or --continuation-indentation Specify the number of spaces to indent on continuation lines when a statement is too long and wraps. - -cli
or --case-indentation- The number of spaces to indent switch when using case. - -cp
or -else-endif-column Place comments at the specified column to the right of else and elseif statements. - -cs or --space-after-cast Leave a space after a cast.
- -d
or -line-comments-indentation Set the indentation for comments that are not placed to the right of code. - -di
or --declaration-indentation Place variables in declaration sections at the specified column. - -fc1 or --format-first-column-comments Set the formatting for comments placed at the very beginning of each line.
- -fca or --format-all-comments Set the formatting of all comments.
- -gnu or --gnu-style Use GNU style formatting; this is the default.
- -i
or --indent-level Set the number of spaces for indentation. - -ip
or --parameter-indentation Set the number of spaces for parameter indentation. - -kr or --k-and-r-style Use Kernighan & Ritchie style formatting.
- -lp or --continue-at-parentheses When a statement wraps and contains parentheses, vertically align the starting column of each line inside the parentheses.
- -nbad or --no-blank-lines-after-declarations Do not add blank lines after declaration sections.
- -nbap or --no-blank-lines-after-procedures Do not add blank lines after procedures.
- -nbbb or --no-blank-lines-after-block-comments Do not add blank lines after block comment sections.
- -nbc or --no-blank-lines-after-commas In declaration sections, do not break lines even when commas appear.
- -ncdb or --no-comment-delimiters-on-blank-lines Do not put comment delimiters on their own line.
- -nce or --dont-cuddle-else Do not place else after "}".
- -ncs or --no-space-after-casts Do not leave a space after a cast.
- -nfc1 or --dont-format-first-column-comments Do not format comments placed at the very beginning of each line.
- -nfca or --dont-format-comments Do not format any comments.
- -nip or --no-parameter-indentation Do not indent parameters.
- -nlp or --dont-line-up-parentheses When a statement wraps and contains parentheses, do not vertically align the starting column of each line inside the parentheses.
- -npcs or --no-space-after-function-call-names Do not add a space after called function names.
- -npro or --ignore-profile Do not read the indent configuration file .indent.pro.
- -npsl or --dont-break-procedure-type Place the procedure type and name on the same line.
- -nsc or --dont-star-comments Do not add an asterisk (*) to the left of comments.
- -nsob or --leave-optional-semicolon Do not remove extra blank lines.
- -nss or --dont-space-special-semicolon If a for or while section contains only one line, do not add a space before the semicolon.
- -nv or --no-verbosity Do not display detailed information.
- -orig or --original Use Berkeley style formatting.
- -pcs or --space-after-procedure-calls Add a space between a called function name and "{".
- -psl or --procnames-start-lines Place the procedure type on the line before the procedure name.
- -sc or --start-left-side-of-comments Add an asterisk (*) to the left of each comment line.
- -sob or --swallow-optional-blank-lines Remove extra blank lines.
- -ss or --space-special-semicolon If a for or while section contains only one line, add a space before the semicolon.
- -st or --standard-output Display the result on standard output.
- -T Indent data type names.
- -ts
or --tab-size Set the tab length. - -v or --verbose Display detailed information during execution.
- -version Display version information.
Indent code formatting notes
| indent options used | Value | Meaning |
|---|---|---|
| --blank-lines-after-declarations | bad | Add a blank line after variable declarations |
| --blank-lines-after-procedures | bap | Add a blank line after functions |
| --blank-lines-before-block-comments | bbb | Add a blank line before block comments |
| --break-before-boolean-operator | bbo | Break long lines before logical operators |
| --blank-lines-after-commas | nbc | Do not break comma-separated variables in declarations |
| --braces-after-if-line | bl | Put "if" and "{" on separate lines |
| --brace-indent 0 | bli0 | Do not continue indenting "{" |
| --braces-after-struct-decl-line | bls | When defining a structure, put "struct" and "{" on separate lines |
| --comment-indentationn | c33 | Comments after statements start at column 33 |
| --declaration-comment-columnn | cd33 | Comments after variable declarations start at column 33 |
| --comment-delimiters-on-blank-lines | ncdb | Do not convert single-line comments to block comments |
| --cuddle-do-while | ncdw | Put the "while" of "do --- while" and the preceding "}" on a new line |
| --cuddle-else | nce | Put "else" and the preceding "}" on a new line |
| --case-indentation 0 | cli0 | Indent case statements in switch by 0 spaces |
| --else-endif-columnn | cp33 | Comments after #else and #endif start at column 33 |
| --space-after-cast | cs | Add a space after type casts |
| --line-comments-indentation n | d0 | Do not outdent single-line comments (those not starting at column 1) |
| --break-function-decl-args | nbfda | Disable: one function parameter per line |
| --declaration-indentationn | di2 | In variable declarations, variables start on line 2, i.e., no alignment needed |
| --format-first-column-comments | nfc1 | Do not format comments starting at the first column |
| --format-all-comments | nfca | Do not enable the switch that formats all comments |
| --honour-newlines | hnl | Prefer to break long lines at the position of newlines in the input. |
| --indent-leveln | i4 | Set the number of characters for indentation. If it is a multiple of tab, use tabs for indentation; otherwise, pad with spaces. |
| --parameter-indentationn | ip5 | In old-style function definitions, indent parameter declarations by 5 spaces |
| --line-length 75 | l75 | Maximum length of non-comment lines is 75 |
| --continue-at-parentheses | lp | Continuation lines start from the parentheses that appeared on the previous line |
| --space-after-procedure-calls | pcs | Insert a space between a function and "(" |
| --space-after-parentheses | nprs | Do not insert a space after "(" or before ")" |
| --procnames-start-lines | psl | Define the function name and return type on two separate lines |
| --space-after-for | saf | Add a space after for |
| --space-after-if | sai | Add a space after if |
| --space-after-while | saw | Add a space after while |
| --start-left-side-of-comments | nsc | Do not add * in generated block comments |
| --swallow-optional-blank-lines | nsob | Do not remove optional blank lines |
| --space-special-semicolon | nss | For single-line for or while statements, do not add a space before ";". |
| --tab-size | ts4 | One tab equals 4 spaces (must divide evenly into "-in") |
| --use-tabs | ut | Use tabs for indentation |
Linux Command Reference