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
282 views
in Technique[技术] by (71.8m points)

How to configure vim to not put comments at the beginning of lines while editing python files

When I add a # in insert mode on an empty line in Vim while editing python files, vim moves the # to the beginning of the line, but I would like the # to be inserted at the tab level where I entered it.

For example, when writing this in vim

for i in range(10):
    #

the # does not stay there where I entered it.

It is moved like so, by vim.

for i in range(10):
#

Does anyone know of a configuration item in vim that would change this?

If it helps, I am using Ubuntu 8.10.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I found an answer here http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash

It seems that the vim smartindent option is the cause of the problem. The referenced page above describes work-a-rounds but after reading the help in smartindent in vim itself (:help smartindent), I decided to try cindent instead of smartindent.

I replaced

set smartindent

with

set cindent

in my .vimrc file

and so far it is working perfectly.

This changed also fixed the behavior of '<<' and '>>' for indenting visual blocks that include python comments.

There are more configuration options for and information on indentation in the vim help for smartindent and cindent (:help smartindent and :help cindent).


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

...