当我编辑 Python 文件时,例如:
def my_func():
print('Something')
<-- CURSOR IS HERE
我想通过输入添加评论#
,该行会自动重新缩进到该行的开头:
def my_func():
print('Something')
#<-- CURSOR IS HERE
我发现这是一个效果smartindent
选项,所以要修复它,我只需运行:set nosi
(或者在我的 .vimrc 中禁用它)。
但在 Vim 的帮助下,:h 'smartindent'
,您可以阅读以下内容:
当 'cindent' 打开或设置 'indentexpr' 时,设置 'si' 无效。
But my indentexpr
选项设置为以下内容:
:set indentexpr?
indentexpr=GetPythonIndent(v:lnum)
我当然应该避免使用smartindent
根本没有选项,因为它看起来是一个旧功能,并且设计为仅适用于 C 风格语言;
但我想知道为什么smartindent
考虑到帮助中写的内容,当我编辑 python 文件时确实有一些效果吗?
是的,它的行为确实与您解释的方式相同。
就我而言:echo GetPythonIndent(v:lnum)
回报-1
:h indentexpr
有以下文字解释该行为。
The expression must return the number of spaces worth of indent. It
can return "-1" to keep the current indent (this means 'autoindent' is
used for the indent).
正如我们设定的si
,它接管ai
.
Now :h si
建议解决方法:
:inoremap # X^H#
where ^H is entered as Ctrl + V Ctrl + H
我相信您会得到比所提供的解决方案更好的解决方案
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)