簡體   English   中英

Vim - 在 Python 中用空格縮進

[英]Vim - indent with spaces in Python

我一直在使用 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 |

到目前為止一切正常。 但我注意到與其他編輯器不同,例如 vscode 或 sublime。 Vim 不會在代碼之間的行間隙中保持縮進。

cursor 將在我按enter時自行縮進,但如果我在返回該行時將該行留空,則 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

這是應該的嗎?

這是應該的嗎?

是的,如果該行沒有代碼,則無需縮進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM