简体   繁体   English

如何在vim中关闭双缩进?

[英]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. 我正在编写python,javascript,html和其他配置文件,我意识到当我输入换行到未完成的行(即未终止的字符串,仍在字典括号内等)时,我会得到双缩进。

How do I fix this? 我该如何解决?

Python 蟒蛇

There are a few variables you can set in your .vimrc file to affect how Python is indented: 您可以在.vimrc文件中设置一些变量来影响Python的缩进方式:

Indent after an open parenthesis: let g:pyindent_open_paren = '&sw * 2' 在打开括号后缩进: let g:pyindent_open_paren = '&sw * 2'

Indent after a nested parenthesis: let g:pyindent_nested_paren = '&sw' 嵌套括号后缩进: let g:pyindent_nested_paren = '&sw'

Indent for a continuation line: let g:pyindent_continue = '&sw * 2' 缩进续行: let g:pyindent_continue = '&sw * 2'

For more info: :help ft-python-indent 有关更多信息:: :help ft-python-indent

Javascript 使用Javascript

See $VIMRUNTIME/indent/javascript.vim : it uses cindent to perform indentation. 请参阅$VIMRUNTIME/indent/javascript.vim :它使用cindent执行缩进。 cindent is affected by a number of options through the cinoptions variable. cindent通过cinoptions变量受到许多选项的影响。 Some of them are set by default to &shiftwidth * 2 , you might want to reset those. 其中一些默认设置为&shiftwidth * 2 ,您可能需要重置它们。

The relevant option for your case seems to be +N . 您案件的相关选项似乎是+N In your .vimrc file you should put something like: .vimrc文件中,您应该输入以下内容:

set cinoptions+=+1

even though this seems to be the default already. 即使这似乎已经是默认值。

Html HTML

Again, see $VIMRUNTIME/indent/html.vim : this performs the indentation via a custom expression. 再次,请参阅$VIMRUNTIME/indent/html.vim :这将通过自定义表达式执行缩进。 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/ . 在最坏的情况下,您可能希望自己修改该文件并将其放在~/.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. 通常,每个文件都根据自己的标准缩进,查看$VIMRUNTIME/indent/以了解是否以及如何配置它们。

Are you sure it is actually indenting twice? 你确定它实际上是两次缩进吗? It may just be that your shiftwidth value is twice the indent length. 可能只是你的shiftwidth值是缩进长度的两倍。 First make sure to set your shiftwidth value to the same value as your indent length. 首先确保将shiftwidth值设置为与缩进长度相同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM