Linux indent command
The Linux indent command is used to adjust the formatting of C source code files.
indent can recognize C source code files and format them to make them easier for programmers to read.
Syntax
indent [参数][源文件] 或 indent [参数][源文件][-o 目标文件]
Parameters:
- -bad or --blank-lines-after-declarations Add a blank line 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 to a new line when a comma appears.
- -bl or --braces-after-if-line The "{" following an if (or else, for, etc.) is on a different line from the execution block, and "}" is on its own line.
- -bli<indent spaces> or --brace-indent<indent spaces> Set the number of spaces for indenting { }.
- -br or --braces-on-if-line The "{" following an if (or else, for, etc.) is on the same line as the execution block, and "}" is on its own line.
- -bs or --blank-before-sizeof Add a space after sizeof.
- -c<column> or --comment-indentation<column> Place comments at the specified column to the right of the program code.
- -cd<column> or --declaration-comment-column<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 execution block).
- -ci<indent spaces> or --continuation-indentation<indent spaces> When a statement is too long and wraps, specify the number of spaces to indent after the line break.
- -cli<indent spaces> or --case-indentation<indent spaces> The number of spaces to indent the switch when using case.
- -cp<column> or --else-endif-column<column> Place comments at the specified column to the right of else and else-if statements.
- -cs or --space-after-cast Add a space after a cast.
- -d<indent spaces> or --line-comments-indentation<indent spaces> Set the indentation spaces for comments that are not placed to the right of program code.
- -di<column> or --declaration-indentation<column> Place the variables in declaration sections at the specified column.
- -fc1 or --format-first-column-comments Set the format for comments placed at the very beginning of each line.
- -fca or --format-all-comments Set the format for all comments.
- -gnu or --gnu-style Specify the use of GNU style; this is the default.
- -i<spaces> or --indent-level<spaces> Set the number of spaces for indentation.
- -ip<spaces> or --parameter-indentation<spaces> Set the indentation spaces for parameters.
- -kr or --k-and-r-style Specify the use of Kernighan & Ritchie style.
- -lp or --continue-at-parentheses When a statement is too long and wraps, and the statement contains parentheses, vertically align the starting column of each line inside the parentheses.
- -nbad or --no-blank-lines-after-declarations Do not add a blank line after declaration sections.
- -nbap or --no-blank-lines-after-procedures Do not add a blank line after procedures.
- -nbbb or --no-blank-lines-after-block-comments Do not add a blank line after block comment sections.
- -nbc or --no-blank-lines-after-commas In declaration sections, do not break to a new line even when a comma appears.
- -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 add 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 is too long and wraps, and the statement 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 the names of called functions.
- -npro or --ignore-profile Do not read indent's configuration file .indent.pro.
- -npsl or --dont-break-procedure-type Put the procedure type and the procedure 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 process extra blank lines.
- -nss or --dont-space-special-semicolon If the for or while section has 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.
- -pcs or --space-after-procedure-calls Add a space between the called function name and "{".
- -psl or --procnames-start-lines Put the procedure type on the line before the procedure name.
- -sc or --start-left-side-of-comments Add an asterisk (*) to the left side of each comment line.
- -sob or --swallow-optional-blank-lines Delete extra blank lines.
- -ss or --space-special-semicolon If the for or while section has only one line, add a space before the semicolon.
- -st or --standard-output Display the result on the standard output device.
- -T Indent data type names.
- -ts<spaces> or --tab-size<spaces> Set the length of the tab.
- -v or --verbose Display detailed information during execution.
- -version Display version information.
Indent code formatting description
| indent parameters 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 the end of a function. |
| --blank-lines-before-block-comments | bbb | Add a blank line before block comments. |
| --break-before-boolean-operator | bbo | For longer lines, break before logical operators. |
| --blank-lines-after-commas | nbc | In variable declarations, do not break lines at comma-separated variables. |
| --braces-after-if-line | bl | Put "if" and "{" on two separate lines. |
| --brace-indent 0 | bli0 | Do not further indent "{". |
| --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 into block comments. |
| --cuddle-do-while | ncdw | For "do --- while", put "while" and the preceding "}" on a new line. |
| --cuddle-else | nce | Put "else" and the preceding "}" on a new line. |
| --case-indentation 0 | cli0 | The case statements in switch are indented 0 spaces. |
| --else-endif-columnn | cp33 | Comments after #else, #endif start at column 33. |
| --space-after-cast | cs | Add a space after type conversion |
| --line-comments-indentation n | d0 | Single-line comments (not starting from column 1) are not indented to the left |
| --break-function-decl-args | nbfda | Off: function parameters one per line |
| --declaration-indentationn | di2 | Variable declarations, variables start on line 2, i.e., alignment is not required |
| --format-first-column-comments | nfc1 | Do not format comments starting on the first line |
| --format-all-comments | nfca | Do not enable the switch for formatting all comments |
| --honour-newlines | hnl | Prefer to break long lines at the position of newlines in the input. |
| --indent-leveln | i4 | Set the indentation to how many characters; if it is an integer multiple of a tab, use tabs for indentation, otherwise use spaces. |
| --parameter-indentationn | ip5 | In old-style function definitions, parameter descriptions are indented 5 spaces |
| --line-length 75 | l75 | Longest non-comment line is 75 |
| --continue-at-parentheses | lp | Continuation lines start from the parenthesis appearing on the previous line |
| --space-after-procedure-calls | pcs | Insert a space between the function and "(" |
| --space-after-parentheses | nprs | Do not insert spaces after "(" or before ")" |
| --procnames-start-lines | psl | Define the function name and return type on two lines |
| --space-after-for | saf | Space after for |
| --space-after-if | sai | Space after if |
| --space-after-while | saw | Space after while |
| --start-left-side-of-comments | nsc | Do not add * in generated block comments |
| --swallow-optional-blank-lines | nsob | Do not remove blank lines that can be added |
| --space-special-semicolon | nss | For a one-line for or while statement, no space before ";" |
| --tab-size | ts4 | One tab is 4 spaces (must divide "-in" evenly) |
| --use-tabs | ut | Use tabs for indentation |
Linux command reference