http://vim.wikia.com/wiki/Converting_tabs_to_spaces
To insert space characters whenever the tab key is pressed, set the ‘expandtab’ option:
:set expandtab
With this option set, if you want to enter a real tab character use Ctrl-V key sequence.
To control the number of space characters that will be inserted when the tab key is pressed, set the ‘tabstop’ option. For example, to insert 4 spaces for a tab, use:
:set tabstop=4
After the ‘expandtab’ option is set, all the new tab characters entered will be changed to spaces. This will not affect the existing tab characters. To change all the existing tab characters to match the current tab settings, use:
:retab
To change the number of space characters inserted for indentation, use the ‘shiftwidth’ option:
:set shiftwidth=4
For example, to get the following coding style,
No tabs in the source file.
All tab characters are 4 space characters.
use the following set of options:
:set tabstop=4
:set shiftwidth=4
:set expandtab
Add the above settings to your vimrc.
Vim中Tab与空格的设置
本文介绍如何在Vim编辑器中将Tab键输入转换为空格,包括设置expandtab选项使Tab键插入空格、使用tabstop选项控制每个Tab键插入的空格数、使用shiftwidth选项调整缩进的空格数等技巧。
741

被折叠的 条评论
为什么被折叠?



