Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is this what it suppose to be?

Yes, if there is no code on the line, then there is no need to indent it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...