0

I'm using neovim and a init.lua file.

In what follows X will indicate the cursor:

for i in range(1,5):
    print(iX

Then I press o:

for i in range(1,5):
    print(i)
    X

Then I press backspace:

for i in range(1,5):
    print(i)
X

So far so good.

Now I press o:

for i in range(1,5):
    print(i)

    X

I don't want this.

I want:

for i in range(1,5):
    print(i)
vim -Nu NONE --cmd "filetype plugin indent on"
X

After reading this, I set :set nosmartindent without success.

Note that indentexpr=nvim_treesitter#indent().

3
  • I have tried to set autoindent, which should "Copy indent from current line when starting a new line",but I obtain the same result, although there is no indent on the previous line (and so the cursor should be at the start). Feb 19 at 8:19
  • can't reproduce it, what is your setup?
    – Maxim Kim
    Feb 19 at 9:12
  • Possibly related: what is the value of the indentkeys option?
    – D. Ben Knoble
    Feb 21 at 16:55

1 Answer 1

0

Indentation for python is set with set indentexpr, if you have:

filetype plugin indent on

in your configuration, then upon opening python file your indentexpr would be set to python#GetIndent(v:lnum) -- function that calculates indent for a current line.

With vim -Nu NONE --cmd "filetype plugin indent on" test.py it works just how you would like it to work.

asciicast

9
  • I didn't understand. python#GetIndent(v:lnum) is good? so I should set it to this value? What I have to do? Feb 19 at 9:22
  • @robertspierre, it should be set automatically if you have filetype plugin indent on in your configuration.
    – Maxim Kim
    Feb 19 at 9:23
  • I have indentexpr=nvim_treesitter#indent() (I didn't set it to this value manually. So I think the treesitter plugin set it?). I'm also using a init.lua, not init.vim. Feb 19 at 9:24
  • In other words, try command vim -Nu NONE --cmd "filetype plugin indent on" test.py and see if the issue is still there.
    – Maxim Kim
    Feb 19 at 9:25
  • @robertspierre, oh. You should have specified you use neovim in the first place.
    – Maxim Kim
    Feb 19 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.