[英]Vim: get autoindent but not smart indent in Python source files
如何配置vim
得到autoindent
,即一个新的行会自动缩进到相同的深度前面的一个,但不是smartindent
(或cindent
?)其中一个额外的标签与结束行之后插入“:”?
我习惯在编写Python(和C)时输入def f(x):<Ret><Tab>...
,因此,使用smartindent
,方法(或循环)中的第一行最终被“双标签”(一个来自智能缩进,另一个来自我按下Tab键)。
此处针对特定文件类型关闭autindent
的说明将关闭autindent
。 我可以获得修改当前文件(同一页面)的说明; 显然:setlocal indentexpr=
是关键,但是当我尝试在.vimrc
执行类似的命令set ...
,我再次破坏了autoindent。
'cindent'
说'cindent'
:有人告诉我,如果您喜欢'smartindent'
话,请使用'cindent'
而不是'smartindent'
(似乎不是)。
在python文件内部,通过'indentexpr'
配置缩进,该缩进设置为$VIMRUNTIME/indent/python.vim
GetPythonIndent(v:lnum)
(如果vimrc中具有filetype plugin indent on
)。 如果使用setlocal indentexpr=
删除它,则该缓冲区没有缩进。
好像你可能想的是,只要你按禁用额外缩进<cr>
在插入模式。 您可以使用:set indentkeys-=o
做到这一点。
有关更多选项,请参见:help cinkeys-format
。 也绝对值得一读:help 'cinkeys'
更好地理解'indentexpr'
和'indentkeys'
以及'cindent'
和'cinkeys'
工作方式。
如果您需要进一步的帮助,我很乐意修改我的回答; 我不确定您可以在以下时间后关闭autindent :
我认为您要的只是添加
set autoindent nosmartindent nocindent
到您通过帖子中包含的链接创建的$ HOME / .vim / indent / python.vim文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.