简体   繁体   中英

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:

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. Vim does not keep the indent in a line gap between code.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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