Neovim自动识别细微差别
我刚刚从VIM切换到Neovim。以下vim配置设置从凹痕中获得我想要的行为:
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set backspace=indent,eol,start
这里的相关部分是自动设置:
set autoindent
在每个newline上,这会导致VIM匹配上一行的凹痕:
def demo_autoindent():
a = 'This line was manually indented'
····
a
的声明是手动的缩进了一个步骤,但第二行被自动识别到同一水平。这里我已经用一系列·
字符表示自动结合。
neovim匹配此行为。但是,Neovim试图对块有点聪明,或者在这种情况下,在Python中宣布词典:
def example_neovim():
b = {
············
请注意,Neovim具有 自动识别这一行。如果有的话,它将具有与b
的声明相同的4空间缩进。相反,Neovim增加了一个额外的两个凹痕,使总数达到了12个空间。
显然,它打算做的是添加一个进一步的缩进:
def example_neovim_intention():
c = {
········
我如何将Neovim配置为:
- 匹配VIM的行为,只是自动识别到同一级别。
- 声明dict时,添加单个(而不是双重)额外的缩进。
I've just switched from vim to neovim. The following vim config settings get the behaviour I want from indentation:
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set backspace=indent,eol,start
The relevant part here is the autoindent:
set autoindent
On each newline, this causes vim to match the indentation of the previous line:
def demo_autoindent():
a = 'This line was manually indented'
····
The declaration of a
was manually indented one step, but the second line was auto-indented to the same level. Here I have represented the auto-indent with a series of ·
characters.
Neovim matches this behaviour. However, Neovim tries to be a bit clever with blocks, or in this case declaring dictionaries in python:
def example_neovim():
b = {
············
Note that Neovim has not auto-indented this line. If it had, it would have the same 4-space indent as the declaration of b
. Instead, Neovim has added an extra two indents, bringing the total to 12-spaces.
Clearly what it intends to do is add one further indent:
def example_neovim_intention():
c = {
········
How do I configure Neovim to either:
- Match the behaviour of vim, just auto-indent to the same level.
- Add a single (rather than a double) extra indent when declaring e.g. a dict.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正面临着完全相同的问题,我使用了VIM很长时间,最近我转到Neovim。
除“ Python”外,其他所有语言的自动凹陷都很好。我发现该文档非常有用: https://neovim.io/doc/doc/doc/user/indent/indent/indent/indent .html#_python 。
Neovim将检查此变量
g:python_indent
,如果未定义,将创建一个默认一个,并且它将是这样(Neovim 0.8.2):更改这些属性/code>,
open_paren
和loss_paren_align_last_line
如下。另一种方法
可以更轻松地解决怪异的凹痕问题。它在我这边起作用,但也许根据以下答复越野车。
设置 nvim-treesitter/nvim-treesitter/nvim-treesitter 并打开树木 - sitter的抚养功能。
I was facing exactly the same issue, I used VIM for quite a long time and recently I switch to NeoVim.
Auto indention on for every other languages except "python" works well. I found this document quite useful: https://neovim.io/doc/user/indent.html#_python.
NeoVim will check this variable
g:python_indent
, if it is not defined a default one will be created, and it would be something like this (NeoVim 0.8.2):Change these properties
continue
,open_paren
andclosed_paren_align_last_line
as follows.Another Approach
This can fix the weird indention issue easier. It work on my side, but maybe buggy according to the replies below.
Setup nvim-treesitter/nvim-treesitter and turn on tree-sitter's indention feature.