Indent settings in vim

Source: Internet
Author: User

1 shiftwidth

This is the blank length indication used for automatic indentation in the program. In general, to keep the program beautiful, it is best to be consistent with the following parameters. It is also the setter of the symbol shift length.

2 tabstop

It is recommended to set the length of spaces equivalent to the tab value to 8, because if it is another value, it may make the file look awkward in printing and other fields. Unless you have set the expandtab mode, that is, to convert tabs into spaces, it will not be confused together. However, after all, the most common setting is to use 8 as a tab, therefore, do not change it.

3 softtabstop

What if we want to change the indentation in the program? If shiftwidth is different from tabstop, you will find the program ugly. At this time, softtabstop will take effect. You can see from the vim description that once the softtabstop value is set, you press the tab key to insert a mix of spaces and tab tabs. The specific mixing depends on the softtabstop you set, for example, if softtabstop is set to 8, press the tab key to insert a normal tab. If softtabstop is set to 16, two tabs are inserted; if softtabstop = 12, a tab is inserted with four spaces. What if softtabstop = 4? At the beginning, there are four spaces inserted. Once you press the tab again, the four spaces will be combined with the previous four spaces to become a tab. In other words, softtabstop is "every 8 spaces into 1 tab", provided that you tabstop = 8.

4 about expandtab

For example, when multiple developers develop projects together, in order to keep the code style as consistent as possible, it is generally not allowed to use the TAB character in the code, instead of four spaces. You can edit an object that contains the following content:
Set shiftwidth = 4
Set expandtab

Then add the following command to. vimrc:
Autocmd FileType c, cpp set shiftwidth = 4 | set expandtab

You can implement this setting only when editing the c and cpp files.

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.