neovim auto-indentation nuances

Viewed 1311

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:

  1. Match the behaviour of vim, just auto-indent to the same level.
  2. Add a single (rather than a double) extra indent when declaring e.g. a dict.
1 Answers

The issue was that neovim has filetype-indentation enabled by default:

:filetype
filetype detection:ON  plugin:ON  indent:ON

Adding the following to my neovim init restored the basic auto-indent functionality:

filetype indent off

This is unsatisfactory. I suspect that the file-type detection is conflicting (or doubling) some other indent config that I have, but I haven't missed it since disabling it.

Related