简体   繁体   English

Vim - 在 Python 中用空格缩进

[英]Vim - indent with spaces in Python

I've been using Vim for a while heard people saying indent with spaces is a better practice when programming in Python so I configured my.vimrc as below:我一直在使用 Vim 一段时间,听到有人说在 Python 中编程时,用空格缩进是一种更好的做法,所以我将 my.vimrc 配置如下:

au BufNewFile,BufRead *.py,*.java,*.cpp,*.c,*.h,*.md,*.html,*.css,*.js
    \ set expandtab |
    \ set tabstop=4 |
    \ set softtabstop=4 |
    \ set shiftwidth=4 |
    \ set textwidth=120 |
    \ set autoindent |
    \ set fileformat=unix |

Everything works well so far.到目前为止一切正常。 But I noticed unlike other editors for example vscode or sublime.但我注意到与其他编辑器不同,例如 vscode 或 sublime。 Vim does not keep the indent in a line gap between code. Vim 不会在代码之间的行间隙中保持缩进。

The cursor will indent itself when I hit enter but if I leave that line blank when I return to that line the cursor will appear at the beginning of the line. cursor 将在我按enter时自行缩进,但如果我在返回该行时将该行留空,则 cursor 将出现在该行的开头。

Here is an example (@ as cursor):这是一个示例(@ 作为光标):

Class RandomClass:
    code... # 1) hit <enter> and change line
    @ # 2) cursor will appear in here. auto indented. good 3) now hit <enter> again and leave this as a line gap
    code... # 4) code something and 5) return back to the line gap

    # 6) now the cursor '@' would appear at the beginning of the line without indentation

Is this what it suppose to be?这是应该的吗?

Is this what it suppose to be?这是应该的吗?

Yes, if there is no code on the line, then there is no need to indent it.是的,如果该行没有代码,则无需缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM