如何配置vim在编辑python文件时不在行首添加注释 [英] How to configure vim to not put comments at the beginning of lines while editing python files
问题描述
当我在编辑 python 文件时在 Vim 的空行上添加 # 以插入模式时,vim 将 # 移动到行的开头,但我希望将 # 插入到我输入它的选项卡级别.
When I add a # in insert mode on an empty line in Vim while editing python files, vim moves the # to the beginning of the line, but I would like the # to be inserted at the tab level where I entered it.
例如,在 vim 中编写时
For example, when writing this in vim
for i in range(10):
#
# 不会留在我输入的地方.
the # does not stay there where I entered it.
它是这样被vim移动的.
It is moved like so, by vim.
for i in range(10):
#
有谁知道 vim 中的配置项会改变这一点?
Does anyone know of a configuration item in vim that would change this?
如果有帮助,我使用的是 Ubuntu 8.10.
If it helps, I am using Ubuntu 8.10.
推荐答案
我在这里找到了答案 http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash
看来vim smartindent 选项是问题的原因.上面引用的页面描述了工作循环,但在阅读了 vim 本身的 smartindent 帮助 (:help smartindent) 后,我决定尝试使用 cindent 而不是 smartindent.
It seems that the vim smartindent option is the cause of the problem. The referenced page above describes work-a-rounds but after reading the help in smartindent in vim itself (:help smartindent), I decided to try cindent instead of smartindent.
我换了
set smartindent
与
set cindent
在我的 .vimrc 文件中
in my .vimrc file
到目前为止,它运行良好.
and so far it is working perfectly.
此更改还修复了<<"的行为和 '>>' 用于缩进包含 Python 注释的可视块.
This changed also fixed the behavior of '<<' and '>>' for indenting visual blocks that include python comments.
在 smartindent 和 cindent 的 vim 帮助中有更多关于缩进的配置选项和信息(:help smartindent 和 :help cindent).
There are more configuration options for and information on indentation in the vim help for smartindent and cindent (:help smartindent and :help cindent).
这篇关于如何配置vim在编辑python文件时不在行首添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!