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 facilitate reading by programmers.
Syntax
indent [options][source file] or indent [options][source file][-o target file]
Options:
-bador--blank-lines-after-declarations: Add blank lines after declaration sections.-bapor--blank-lines-after-procedures: Add blank lines after procedures.-bbbor--blank-lines-after-block-comments: Add blank lines after block comments.-bcor--blank-lines-after-commas: Break lines after commas in declarations.-blor--braces-after-if-line: Place braces on a new line after control statements likeif,else,for, etc.-bli<number>or--brace-indent<number>: Set the number of spaces for brace indentation.-bror--braces-on-if-line: Place braces on the same line as control statements likeif,else,for, etc.-bsor--blank-before-sizeof: Add a space aftersizeof.-c<number>or--comment-indentation<number>: Place comments in specified columns to the right of the code.-cd<number>or--declaration-comment-column<number>: Place comments in specified columns to the right of declarations.-cdbor--comment-delimiters-on-blank-lines: Place comment delimiters on their own line.-ceor--cuddle-else: Placeelseright after the closing brace}.-ci<number>or--continuation-indentation<number>: Set the indentation level after line breaks.-cli<number>or--case-indentation-<number>: Set the indentation level forcasestatements.-cp<number>or-else-endif-column<number>: Place comments in specified columns to the right ofelseandelseifstatements.-csor--space-after-cast: Add a space aftercast.-d<number>or-line-comments-indentation<number>: Set the indentation level for comments not aligned to the right of the code.-di<number>or--declaration-indentation<number>: Place variables in declaration sections in specified columns.-fc1or--format-first-column-comments: Format comments placed at the beginning of each line.-fcaor--format-all-comments: Format all comments.-gnuor--gnu-style: Use GNU style formatting, which is the default.-i<number>or--indent-level<number>: Set the number of spaces for indentation.-ip<number>or--parameter-indentation<number>: Set the indentation level for parameters.-kror--k-and-r-style: Use Kernighan & Ritchie style formatting.-lpor--continue-at-parentheses: Align the content of parentheses vertically when a statement is broken over multiple lines.-nbador--no-blank-lines-after-declarations: Do not add blank lines after declaration sections.-nbapor--no-blank-lines-after-procedures: Do not add blank lines after procedures.-nbbbor--no-blank-lines-after-block-comments: Do not add blank lines after block comments.-nbcor--no-blank-lines-after-commas: Do not break lines after commas in declarations.-ncdbor--no-comment-delimiters-on-blank-lines: Do not place comment delimiters on their own line.-nceor--dont-cuddle-else: Do not placeelseright after the closing brace}.-ncsor--no-space-after-casts: Do not add a space aftercast.-nfc1or--dont-format-first-column-comments: Do not format comments placed at the beginning of each line.-nfcaor--dont-format-comments: Do not format any comments.- -nip or --no-parameter-indentation Parameters should not be indented.
- -nlp or --dont-line-up-parentheses When the narrative is too long and needs to wrap, and the narrative includes parentheses, do not vertically align the starting columns of each line within the parentheses.
- -npcs or --no-space-after-function-call-names Do not add a space after the function name in a call.
- -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 process extra blank lines.
- -nss or --dont-space-special-semicolon Do not add a space before the semicolon if the for or while section is only one line.
- -nv or --no-verbosity Do not display detailed information.
- -orig or --original Use the Berkeley format.
- -pcs or --space-after-procedure-calls Add a space between the called function name and the "{".
- -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 line of comments.
- -sob or --swallow-optional-blank-lines Remove extra blank lines.
- -ss or --space-special-semicolon Add a space before the semicolon if the for or while section is only one line.
- -st or --standard-output Display the result on the standard output device.
- -T Indent the data type name.
- -ts<number> or --tab-size<number> Set the length of the tab.
- -v or --verbose Display detailed information during execution.
- -version Display version information.
Indent Code Formatting Instructions
| Used indent parameter | 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 lines in variable declarations separated by commas |
| --braces-after-if-line | bl | Place "if" and "{" on separate lines |
| --brace-indent 0 | bli0 | "{" does not continue to indent |
| --braces-after-struct-decl-line | bls | Place "struct" and "{" on separate lines in structure definitions |
| --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 turn single-line comments into block comments |
| --cuddle-do-while | ncdw | Place "while" of "do --- while" and the preceding "}" on a new line |
| --cuddle-else | nce | Place "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, #endif start at column 33 |
| --space-after-cast | cs | Add a space after type casting |
| --line-comments-indentation n | d0 | Single-line comments (not starting from column 1) do not indent to the left |
| --break-function-decl-args | nbfda | Disable: Function arguments on one line each |
| --declaration-indentationn | di2 | Variable declarations start at line 2, i.e., do not align |
| --format-first-column-comments | nfc1 | Do not format comments starting from 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 number of characters to indent; if a multiple of the tab size, use tabs; otherwise, use spaces |
| --parameter-indentationn | ip5 | Indent parameter descriptions in old-style function definitions by 5 spaces |
| --line-length 75 | l75 | Maximum line length for non-comment lines is 75 |
| --continue-at-parentheses | lp | Continuation lines start at the parentheses from the previous line |
| --space-after-procedure-calls | pcs | Insert a space between the function and "(" |
| --space-after-parentheses | nprs | Do not insert a space after "(" and before ")" |
| --procnames-start-lines | psl | Place function names and return types on separate lines |
| --space-after-for | saf | Include a space after "for" |
| --space-after-if | sai | Include a space after "if" |
| --space-after-while | saw | Include a space after "while" |
| --start-left-side-of-comments | nsc | Do not add "*" at the start of generated block comments |
| --swallow-optional-blank-lines | nsob | Do not remove optional blank lines |
| --space-special-semicolon | nss | Do not add a space before ";" in single-line for or while statements |
| --tab-size | ts4 | One tab equals 4 spaces (must be divisible by "-in") |
| --use-tabs | ut | Use tabs for indentation |