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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Python
There are a few variables you can set in your
.vimrcfile 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-indentJavascript
See
$VIMRUNTIME/indent/javascript.vim: it usescindentto perform indentation.cindentis affected by a number of options through thecinoptionsvariable. 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.vimrcfile you should put something like: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.