Original converted from [http://my.oschina.net/captaintheron/blog/5157? From = RSS]
It is annoying that python is strictly indented, but I use py under Vim in Linux. By default, the tab is as long as eight spaces (in fact, it is still a tab, set tabstop = 4 is used to change the number of indentations. It is still a tab. It is still abnormal to get win. : Set softtabstop = 4
The same is true, so Google follows the principle that "the foreign affairs are unknown to Google, the internal affairs are unknown to Baidu, and the housing affairs are unknown to Tianya. You can also set expandtab to replace the Tab character with spaces to ensure consistent indentation across platforms.
The original text is as follows:
'Tabstop' is set to 8 by default. Although you can change it, you will soon be in trouble. Others
The program does not know the value of the tab interval you use, and your file will suddenly change a lot. In addition
For multiple printers, the tab interval value is fixed to 8. So it is best to keep the 'tabstop' value unchanged. (If you compile
For files that use other tab Interval Values, see | 25.3 | .)
If you use eight spaces to indent the program, you will soon go to the rightmost side of the window.
There are not enough differences. Therefore, many users prefer to use four spaces. This is indeed a good compromise.
Because a tab (<Tab>
) Is 8 spaces, and you want to use 4 spaces to indent, so that you do not have
Tab to complete indentation. There are two solutions:
1. Use both tabs and spaces. Because a tab occupies 8 spaces, your file will contain less
The number of bytes. Inserting or deleting a tab is much faster than eight spaces.
2. Use Only spaces. This avoids the trouble of using files with different tab values.
Fortunately, VIM supports both methods.
Mixed Use of empty cells and table Operators
If you use a combination of tabs and spaces, You can edit them as normal. By default
Handle these situations well.
Setting 'softtabstop' makes work easier. This option enables<Tab>
Looks like
It is set to the value specified by 'softtabstop', but it is actually a combination of tabs and spaces.
After you execute the following command<Tab>
The cursor moves to the next "4 columns" side.
World:
:set softtabstop=4
When you press<Tab>
After the key, four spaces will be inserted into the text; press again<Tab>
Key, VIM will
Delete the four spaces and then insert a tab. Vim tries its best to use tabs with spaces
Fill.
Deletion is performed in the opposite way.<BS>
The key always deletes the specified number of 'softtabstop. Vim
You can use tabs and spaces to fill the gaps.
The following example shows how to input a tab multiple times and then use<BS>
. "." Indicates a space while
"------->" Indicates a tab.
Input result
<Tab>
....
<Tab>
<Tab>
------->
<Tab>
<Tab>
<Tab>
-------> ....
<Tab>
<Tab>
<Tab>
<BS>
------->
<Tab>
<Tab>
<Tab>
<BS>
<BS>
....
Another method is to use the 'smarttab' option. When it is set, VIM uses
'Shiftwidth', and<Tab>
Use a real tab. However<BS>
Key not
It will work as in the 'softtabstop' option.
Use only null cells
If you do not want to show a tab in the file, you can set the 'pandtab' option:
:set expandtab
When this option is set,<Tab>
The key inserts a series of spaces. In this way, you can insert a tab
The same number of spaces. But your file does not contain real tabs.
Return key (<BS>
) Only one space can be deleted at a time. In this way, if you type<Tab>
, You need to type
8 times<BS>
To be restored. If you are adjusting indentation, enterCTRL-D
It will be faster.
Conversion between table operators and empty cells
Setting the 'pandtab' option does not affect existing tabs. If you want to convert a tab to a space, you can
Run the ": retab" command. Run the following command:
:set expandtab
:%retab
Vim uses spaces instead of tabs in all indentation. However, the tabs after all non-empty characters are not affected.
. If you want to convert these tabs, add them to the command! :
:%retab!
This is not safe. Because it may modify the tabs in the string. To check whether this situation exists, you can execute
Row:
/"[^"\t]*\t[^"]*"
We recommend that you do not directly use tabs in strings. Replace "\ t" with less trouble.
Commands that convert spaces into tabs are the opposite:
:set noexpandtab
:%retab!
If you are interested in VIM configuration, see:
http://vcd.gro.clinux.org/doc/usr_toc.html#usr_toc.txt