tags:

views:

47

answers:

1

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

How do I fix this?

+2  A: 

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.

UncleZeiv
ok what about JS files? What are they considered in that help section (there's no JS file specific options so I don't know which one to pick)
asdca