Python的Vim缩进

2024-03-29 05:36:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我的Vim在:之后缩进时遇到问题。比如说,

with open(filepath, "r") as r_obj:
# Pressing enter comes here
    # Not here
for i in range(100):
    # Indents correctly!
if (condition):
    # Indents correctly!

注意,我使用了vim-python-pep8-indent,可以在here找到它。真正奇怪的是,如果我使用for循环,它将正确缩进,但如果我使用with语句,它不会正确缩进。无论我做什么,它都不会在with语句处正确缩进

我认为缩进与for和if语句有关,因为即使我从indentkeys中删除:<:>,Vim也会正确缩进

另外,请注意,我的当前设置为

:set indentexpr?
# gives 'indentexpr='
:set indentkeys?
# gives 'indentkeys=0{,0},0),0],:,0#,!^F,o,O,e,<:>
:set cindent?
# gives 'nocindent'

在此问题上的任何帮助都将不胜感激


Tags: forifhereaswith语句vimopen