加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Vim自动删除Python上的缩进

发布时间:2020-12-15 16:44:45 所属栏目:安全 来源:网络整理
导读:参见英文答案 How to configure vim to not put comments at the beginning of lines while editing python files7答案我使用Vim和编辑Python脚本。 自动缩进工作相当不错,一般来说,但是当我开始一个新行,并键入’#’键入一个注释,Vim unindents行为我。
参见英文答案 > How to configure vim to not put comments at the beginning of lines while editing python files7答案我使用Vim和编辑Python脚本。

自动缩进工作相当不错,一般来说,但是当我开始一个新行,并键入’#’键入一个注释,Vim unindents行为我。

例如,如果有

def foo():

和我按enter键,Vim将缩进正确

def foo():
    pass

但是,如果不是键入pass,我键入#,它自动取消缩进

def foo():
# comment

class Thing():
    def __init__(self):
         pass
# comment line gets unindented all the way

我的.vimrc文件如下。任何人都知道为什么会发生这种情况?

set tabstop=4
set smartindent
set shiftwidth=4
set expandtab
set backspace=indent,eol,start
set scrolloff=3
set statusline=%f%m%r%h%w [%Y %{&ff}] [%l/%L (%p%%)]
set laststatus=2
设置smartindent使Vim的行为像你描述的我,而使用nosmartindent(这是我倾向于使用),它的行为像你喜欢它。

更新:从smartindent上的文档:

When typing ‘#’ as the first character in a new line,the indent for
that line is removed,the ‘#’ is put in the first column. The indent
is restored for the next line. If you don’t want this,use this
mapping: “:inoremap # X^H#”,where ^H is entered with CTRL-V CTRL-H.
When using the “>>” command,lines starting with ‘#’ are not shifted
right.

这似乎是。

更新:可能不需要打扰以下…我会离开这里为增加信息值。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读