Vim - 在 Python 中用空格缩进
Vim - indent with spaces in Python
我已经使用 Vim 一段时间了,听说有人说在 Python 中编程时使用空格缩进是更好的做法,所以我将我的 .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 |
到目前为止一切正常。 但我注意到它不同于其他编辑器,例如 vscode 或 sublime。 Vim 不会在代码之间的行间距中保持缩进。
当我点击 enter
时,光标会自行缩进,但是如果我在 return 到该行时将该行留空,则光标将出现在该行的开头。
这里是一个例子(@作为光标):
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?
是的,如果一行中没有代码,那么就不需要缩进了。
我已经使用 Vim 一段时间了,听说有人说在 Python 中编程时使用空格缩进是更好的做法,所以我将我的 .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 |
到目前为止一切正常。 但我注意到它不同于其他编辑器,例如 vscode 或 sublime。 Vim 不会在代码之间的行间距中保持缩进。
当我点击 enter
时,光标会自行缩进,但是如果我在 return 到该行时将该行留空,则光标将出现在该行的开头。
这里是一个例子(@作为光标):
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?
是的,如果一行中没有代码,那么就不需要缩进了。