Tab is displayed in vim, and vim input tab is automatically replaced with 4 spaces

1. Display the TAB key
When there is a TAB key in the file, you cannot see it. To show it, bottom line mode:
:set list
Now TAB is shown as ^I, and $ is shown at the end of each line, so you can find where whitespace characters you may have missed.
One disadvantage of this is that it looks ugly when there are many TABs. If you use a colored terminal, or use GUI mode, Vim can highlight spaces and TABs.
Use the 'listchars' option:
:set listchars=tab:>-,trail:-
Now, TAB will be displayed as ">—" and extra blank characters at the end of the line will be displayed as "-". It looks better, doesn't it?

2. Automatically replace with 4 spaces when entering tab:

Add in .vimrc

"TAB
"空格代替Tab"
"注意: 插入模式下输入【ctrl+v+i】可以强制输入一个tab
set tabstop=4     " tabstop 表示一个 tab 显示出来是多少个空格的长度,默认8
set softtabstop=4 " softtabstop 表示在编辑模式的时候按退格键的时候退回缩进的长度,当使用 expandtab 时特别有用
set expandtab     " 当设置成 expandtab 时,缩进用空格来表示,noexpandtab 则是用制表符表示一个缩进
set autoindent    " 自动缩进
set cindent       " 自动缩进补充
set shiftwidth=4  " 自动缩进空白字符个数

3. Replace the existing tabs in the vim text with spaces Enter
in the bottom line mode:

:%retab

Guess you like

Origin blog.csdn.net/weixin_43274923/article/details/122301433
Tab
Tab
Tab
Tab