Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off double indentation in vim?

Tags:

vim

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?

like image 743
asdca Avatar asked Aug 21 '10 20:08

asdca


People also ask

How do I turn on auto indent in Vim?

How to Turn On Auto Indent in Vim. To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing.

How do I turn off auto indent in Vim?

How to Turn Off Vim Auto Indent. You can also temporarily turn off automatic indenting by typing :set paste in command mode. (:unset paste to turn it back on again.) This is useful — as you might guess from the command name — if you're pasting in chunks of text or code to avoid getting annoying extraneous indents.

How do I paste without formatting in Vim?

vim Inserting text Disable auto-indent to paste code And if you want to paste as is from the clipboard. Just press F3 in insert mode, and paste. Press F3 again to exit from the paste mode.


1 Answers

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.

like image 69
UncleZeiv Avatar answered Oct 07 '22 14:10

UncleZeiv