How can I change the automatic indentation inside brackets? Without any configuration, {vim,nvim} does the following:

test = [| # Press enter
test = [
        | # Cursor ends up here, at the same level as the opening bracket

Here's what I'd like to get:

test = [
    | # Cursor should end up here, with one more indentation level than the previous line

Treesitter indentation doesn't seem to help.

This happens in python files amongst others (i.e. filetype=python)

  • 3
    The configuration is usually per filetype. What is the filetype of your buffer :set ft?? Oct 31, 2023 at 12:10
  • 1
    @VivianDeSmedt this happens in python files amongst others (i.e. filetype=python) Oct 31, 2023 at 22:01
  • Do you still have something open in your question (e.g. other file types for which you search a solution)? How can we help you further? Otherwise maybe could you accept one of the answer using the v button next to the arrow voting buttons. It allow the question to rest :-) Nov 6, 2023 at 5:26

1 Answer 1


This automatic indentation is controlled by the indentexpr option.

For python the default procedure is configurable and if you set the following global variable g:pyindent_open_paren to shiftwidth() you'll get the behavior your want:

let g:pyindent_open_paren = shiftwidth()

More information with: :help ft-python-indent

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.