Autoindenting无法在vim中运行?

the*_*lee 7 vim indentation

我目前正在使用vim并且希望每次我需要自动添加(例如在javascript之后或在Python中冒号之后).出于某种原因,我尝试了autoindent和smartindent,但每个新行给了我2个标签而不是一个.它为什么这样做?我以为它只会插入一个标签.

我当前的〜/ .vimrc文件有:

    set ts=4
    set autoindent
    set smartindent
    filetype plugin indent on
Run Code Online (Sandbox Code Playgroud)

zmo*_*zmo 6

你还需要设置:

:set shiftwidth=4 softtabstop=4
Run Code Online (Sandbox Code Playgroud)

tabstop仅用于实际"\ t"选项卡所需的列数:

:he shiftwidth

    Number of spaces to use for each step of (auto)indent.  Used for
    |'cindent'|, |>>|, |<<|, etc.
    When zero the 'ts' value will be used.

:he softtabstop

    Number of spaces that a <Tab> counts for while performing editing
    operations, like inserting a <Tab> or using <BS>.  It "feels" like
    <Tab>s are being inserted, while in fact a mix of spaces and <Tab>s is
    used.
Run Code Online (Sandbox Code Playgroud)

而tabstop:

 :he tabstop

    Number of spaces that a <Tab> in the file counts for.  Also see
    |:retab| command, and 'softtabstop' option.
Run Code Online (Sandbox Code Playgroud)

作为奖励,这里有一些我为此设置的映射,当我需要处理那些不使用我最喜欢的默认扩展选项卡并且有4个空格缩进的项目时:

nmap <Leader>t2 :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
nmap <Leader>t4 :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
nmap <Leader>t8 :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
nmap <Leader>T2 :set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2<CR>
nmap <Leader>T4 :set noexpandtab tabstop=4 softtabstop=4 shiftwidth=4<CR>
nmap <Leader>T8 :set noexpandtab tabstop=8 softtabstop=8 shiftwidth=8<CR>
Run Code Online (Sandbox Code Playgroud)