简体   繁体   中英

How to turn off double indentation in vim?

I am writing python, javascript, html and other config files and I realize that when I enter newline to an unfinished line (ie unterminated string, still inside dictionary brackets, etc) I get double indentation.

How do I fix this?

Python

There are a few variables you can set in your .vimrc file to affect how Python is indented:

Indent after an open parenthesis: let g:pyindent_open_paren = '&sw * 2'

Indent after a nested parenthesis: let g:pyindent_nested_paren = '&sw'

Indent for a continuation line: let g:pyindent_continue = '&sw * 2'

For more info: :help ft-python-indent

Javascript

See $VIMRUNTIME/indent/javascript.vim : it uses cindent to perform indentation. cindent is affected by a number of options through the cinoptions variable. Some of them are set by default to &shiftwidth * 2 , you might want to reset those.

The relevant option for your case seems to be +N . In your .vimrc file you should put something like:

set cinoptions+=+1

even though this seems to be the default already.

Html

Again, see $VIMRUNTIME/indent/html.vim : this performs the indentation via a custom expression. I had a quick look and it doesn't seem to be performing any double indentation anywhere, but I might be wrong. The global variables available for that doesn't seem to be relevant.

In the worst case, you might want to amend that file yourself and put it in your ~/.vim/indent/ .

Other files

In general, each file is indented according to its own criteria, have a look in $VIMRUNTIME/indent/ to understand if and how each of them can be configured.

Are you sure it is actually indenting twice? It may just be that your shiftwidth value is twice the indent length. First make sure to set your shiftwidth value to the same value as your indent length.

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