设置了以下选项:
setlocal formatprg=autopep8\-aa\-
当我在可视模式下选择一行并按下 gq
时,autopep8 对该行进行了修改,但它也改变了该行的缩进:它默认为 4 个空格的缩进,无论行的当前缩进级别如何。我希望它假设这些行缩进正确,所以不要管它们。
同样,如果我为 autopep8
设置 --indent-size 8
开关,它会将行推到 8 个空格的缩进级别。请注意,如果视觉选择足够大以包含顶级缩进(即没有缩进的地方),则所有内容都会正确缩进。但我倾向于在提交之前通过视觉选择较小的 block 。
最佳答案
你需要给 --indent-size 0
。所以我的 .vimrc
有这一行:
" Use gq to clean up code
" Indent to 0 because otherwise it pushes selected lines to the given
" indent-size, no matter the current indent level of the line.
au FileType python setlocal formatprg=autopep8\ -aa\ --indent-size\ 0\ -
关于python - 使用 formatprg=autopep8 时如何设置正确的缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24449056/