Use the indent command to help typeset source code

Source: Internet
Author: User

When writing code, especially when editing code in Vim, you may not pay much attention to the Code style issues, such as the '{' symbol at the end of the line or the beginning of the next line, etc,

In this way, when you merge your code with others' code, there may be different code styles. Here we recommend a command to adjust the code style.

 

In Linux, the indent command is used to adjust the source code typographical style. After the indent parameter is followed, you can set your preferred code style:

 

Indent [Parameter options] [source file] [-O target file];

Or if the target file is not specified, replace the source file directly:Indent [Parameter options] [source file];

 

Parameters:

-Bad or -- blank-lines-after-declarations: Add blank lines to the declaration section.
-Bap or -- blank-lines-after-Procedures add blank lines in the program or.
-BBB or -- blank-lines-after-block-Comments add blank lines after the comment section.
-BC or -- blank-lines-after-commas in the Declaration section, if there is a comma, It is a line break.
-BL or -- braces-after-if-line if (or else, for, and so on) are different from "{" in the subsequent execution section, and "}" is a row.
-Set the number of BLI <shrink cells> or -- brace-indent <shrink cells>.
-Br or -- braces-on-if-line if (or else, for, and so on) are different from the "{" of the subsequent execution segment, and "}" is a row.
-BS or -- blank-before-sizeof is empty after sizeof.
-C <Number of columns> or -- Comment-indentation <Number of columns> place comments in the column specified on the right of the program code.
-CD <Number of columns> or -- Declaration-comment-column <Number of columns> place comments in the column specified on the right of the Declaration.
-The CDB or -- Comment-delimiters-on-blank-lines annotator is a line.
-Ce or -- cuddle-else place the else after "}" (the end of the IF execution segment.
-Ci <Number of reduced bins> or -- continuation-indentation <Number of reduced bins> specifies the number of bins after a line break when the length is too long.
-When you use case-based CLI <contract number> or -- Case-indentation-<contract number>, switch compresses the number of cells.
... (More than a hundred entries are omitted later)

 

You will find that how do you remember so many parameters? My method is that you don't have to remember it. You can simply learn the code style of the Linux kernel,

Therefore, you can open the configuration file in Linux:/Usr/src/kernels/XXX (kernel version)/scripts/lindent

Find the param variable and use its value as your indent parameter so that your code layout style is the same as that of the kernel code.

Param = "-NPRO-Kr-i8-TS8-sob-L80-SS-NCS-CP1" (content opened by the author's host)

 

If you use indent and add such a long string of parameters each time, you will feel very troublesome. I recommend that you use an alias in. bashrc.

Command: (take my habits as an example)

Alias myindent = 'indent-NPRO-Kr-i8-TS8-sob-L80-SS-NCS-cp1'

 

in this way, you can directly use myindent filename to help you typeset source code ~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.