在我的情况下,set indentexpr=
就可以解决问题。
我找到了那些设置令人讨厌行为的配置文件,其中包括 fd python.vim/
。在 /usr/share/vim/vim90/indent/python.vim
中有一行代码 setlocal indentexpr=python#GetIndent(v:lnum)
。函数 python#GetIndent
定义在 /usr/share/vim/vim90/autoload/python.vim
中。该函数返回了一个奇怪的值,非 shiftwidth
和 tabstop
的倍数。因此 vim 插入了一个制表符后跟着一些空格。
现在,我把 indentexpr
设置为空值,我认为 vim 会回退到 autoindent
。 smartindent
和 cindent
已关闭。(https://vimhelp.org/indent.txt.html)
当然,还需要 set noexpandtab
。我不确定其他设置是否相关。
编辑: autoindent
并不完美,它只是将新行缩进与上一行相同。
set smartindent
set cinwords=if,elif,else,try,except,finally,with,for,while,class,def
不如预期工作,cindent
似乎不适用于 Python,因此最终使用 indentexpr
是正确的方法。
幸运的是,缩进函数可以配置,参见 help ft-python-indent
或查看代码 - 这更详细地说明了 disable_parentheses_indenting 功能。看起来这对我来说是解决方案:
if !exists('g:python_indent')
let g:python_indent = {}
endif
let g:python_indent.disable_parentheses_indenting = 1
(https://vi.stackexchange.com/a/38824/43863)
$HOME/vimfiles/after/indent/haml.vim
中。有关更多信息,请查看:help after-directory
。 - Nefrubyr