Vim tab is set in. after the following code is added to vimrc, restart vim to generate four spaces by TAB: set ts = 4 (Note: ts is the abbreviation of tabstop, with four spaces at the TAB width) set expandtab for saved files, use the following method to replace spaces and tabs: TAB with space: set ts = 4: set expandtab: % retab! Replace spaces with TAB: set ts = 4: set noexpandtab: % retab! Add! Is used to process non-blank characters after the TAB, that is, all tabs, if not added !, Only the TAB at the beginning of the line is processed. In. in the vimrc file, enter the following text: set tabstop = 4 set softtabstop = 4 set shiftwidth = 4 set noexpandtab set nu set autoindent set cindent where: Tabstop: the length of spaces displayed on a tab. The default value is 8. Softtabstop: return the indent length when you press the backspace key in edit mode. It is particularly useful when you use expandtab. Shiftwidth: indicates the length of each level of indentation, which is generally set to the same as softtabstop. When it is set to expandtab, the indentation uses spaces to represent noexpandtab, which is a tab to represent an indent. Nu: displays the row number. Autoindent: Indicates automatic indent. Cindent: auto indent especially for C language.