$ # see what changes it would make
$ autopep8 path/to/file.py --select=E101,E121 --diff
$ # make these changes
$ autopep8 path/to/file.py --select=E101,E121 --in-place
注意:E101 and E121是pep8缩进(我认为您可以简单地通过--select=E1来解决所有与缩进相关的问题-那些从E1开始的问题)。
*:ret* *:retab*
:[range]ret[ab][!] [new_tabstop]
Replace all sequences of white-space containing a
<Tab> with new strings of white-space using the new
tabstop value given. If you do not specify a new
tabstop size or it is zero, Vim uses the current value
of 'tabstop'.
The current value of 'tabstop' is always used to
compute the width of existing tabs.
With !, Vim also replaces strings of only normal
spaces with tabs where appropriate.
With 'expandtab' on, Vim replaces all tabs with the
appropriate number of spaces.
This command sets 'tabstop' to the new value given,
and if performed on the whole file, which is default,
should not make any visible change.
Careful: This command modifies any <Tab> characters
inside of strings in a C program. Use "\t" to avoid
this (that's a good habit anyway).
":retab!" may also change a sequence of spaces by
<Tab> characters, which can mess up a printf().
{not in Vi}
Not available when |+ex_extra| feature was disabled at
compile time.
Change Python (.py) files to use
4-space indents and no hard tab
characters. Also trim excess spaces
and tabs from ends of lines, and
remove empty lines at the end of
files. Also ensure the last line ends
with a newline.
我会伸手让autopep8来做这个:
注意:E101 and E121是pep8缩进(我认为您可以简单地通过
--select=E1
来解决所有与缩进相关的问题-那些从E1开始的问题)。可以使用递归标志将此应用于整个项目:
另请参见Tool to convert Python code to be PEP8 compliant。
如果您使用的是Vim,请参见^{} 。
例如,如果您只是键入
所有标签页都将展开到空格中。
你可能想
以确保任何新行都不会使用文字制表符。
如果你不使用Vim
将用空格替换制表符,假设制表符每8个字符停止一次,在
file.py
中(为了以防万一,原始制表符将转到file.py.bak
)。如果您的止动块是每4个空格,则将8s替换为4s。使用在Python安装的
Tools/scripts/
目录中找到的reindent.py
脚本:请查看该脚本以获取详细的使用说明。
相关问题 更多 >
编程相关推荐