【问题标题】:How to set correct indendation when using formatprg=autopep8?使用 formatprg=autopep8 时如何设置正确的缩进?
【发布时间】:2014-08-18 09:36:33
【问题描述】:

使用以下选项集: setlocal formatprg=autopep8\ -aa\ -

当我在可视模式中选择一行并按gq 时,autopep8 会修改该行,但它也会改变该行的缩进:无论当前缩进如何,它默认缩进 4 个空格行的级别。我希望它假设这些行是正确缩进的,所以不要管它们。

同样,如果我为autopep8 设置--indent-size 8 开关,它会将行推到8 个空格的缩进级别。请注意,如果视觉选择足够大以包含顶级缩进(即没有缩进的地方),则所有内容都会正确缩进。但我倾向于在提交之前视觉选择较小的块。

【问题讨论】:

    标签: python vim pep8


    【解决方案1】:

    你需要给--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\ -
    

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 1970-01-01
      • 2023-03-25
      • 2021-10-27
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      相关资源
      最近更新 更多