Strange indent behaviour in (neo)vim with Python

Viewed 30

This issue is reproducible in vim and neovim. I'm using neovim with pretty much default values and no plugins (except the standard file plugins) and noticed a behavior that bothers me for a few years: In some situations vim gets the indenting wrong:

def test():
    a = [<ENTER>

I'd expect the cursor on the next line to be here, e.g. 4 characters indented from the previous line:

def test():
    a = [<ENTER>
        <HERE>

instead, vim consistently shifts by 8 characters and I end up here:

def test():
    a = [<ENTER>
            <HERE>

This behavior is quite consistent in other situations too:

def test():
    for i in range(10):
        a = [<ENTER>
                <HERE>

the cursor is shifted 8 characters instead of 4. My question is: where does that behavior come from and can it be fixed?

The relevant options set automatically by the python file plugin:

shiftround
softtabstop=4
tabstop=4
expandtab
shiftwidth=4

comments=b:#,fb:-
filetype=python
syntax=python
cinkeys=0{,0},0),0],:,!^F,o,O,e
commentstring=# %s
define=^\s*\(def\|class\)
include=^\s*\(from\|import\)
includeexpr=substitute(substitute(substitute(v:fname,b:grandparent_match,b:grandparent_sub,''),b:parent_match,b:parent_sub,''),b:child_match,b:child_sub,'g')
indentexpr=GetPythonIndent(v:lnum)
indentkeys=0{,0},0),0],:,!^F,o,O,e,<:>,=elif,=except
0 Answers
Related