Skip to content

Python intentation brokes after { symbol in quotes #8432

Description

@Dehta-Hun

Describe the bug

If I put the not closed bracket in string then indentation goes on the level of that bracket

Image

To Reproduce

  1. Create string variable containing open bracket (like in screenshoot)
  2. From here any new line will be auto intent at "{" level

Expected behavior

Do not indent based on string content

Output of :checkhealth nvim-treesitter

nvim-treesitter:                                                            ✅

Requirements ~
- ✅ OK Neovim was compiled with tree-sitter runtime ABI version 15 (required >=13).
- ✅ OK tree-sitter-cli 0.25.10 (/usr/bin/tree-sitter)
- ✅ OK tar 1.35.0 (/usr/bin/tar)
- ✅ OK curl 8.17.0 (/usr/bin/curl)
  curl 8.17.0 (x86_64-pc-linux-gnu) libcurl/8.17.0 OpenSSL/3.6.0 zlib/1.3.1 brotli/1.1.0 zstd/1.5.7 libidn2/2.3.8 libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.68.0 nghttp3/1.13.1 mit-krb5/1.21.3
  Release-Date: 2025-11-05
  Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
  Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

OS Info ~
- sysname: Linux
- machine: x86_64
- release: 6.13.0-4-rt5-MANJARO
- version: #1 SMP PREEMPT_RT Mon May  5 20:48:44 UTC 2025

Install directory for parsers and queries ~
- /home/mironov_a/.local/share/nvim/site/
- ✅ OK is writable.
- ✅ OK is in runtimepath.

Installed languages     H L F I J ~
- astro                 ✓ ✓ ✓ ✓ ✓
- bash                  ✓ ✓ ✓ ✓ ✓
- c                     ✓ ✓ ✓ ✓ ✓
- css                   ✓ . ✓ ✓ ✓
- diff                  ✓ . ✓ . ✓
- ecma
- editorconfig          ✓ . ✓ . ✓
- gitcommit             ✓ . . . ✓
- go                    ✓ ✓ ✓ ✓ ✓
- gomod                 ✓ . . . ✓
- gosum                 ✓ . . . .
- gowork                ✓ . . . ✓
- graphql               ✓ . . ✓ ✓
- html                  ✓ ✓ ✓ ✓ ✓
- html_tags
- javascript            ✓ ✓ ✓ ✓ ✓
- jsdoc                 ✓ . . . .
- json                  ✓ ✓ ✓ ✓ ✓
- json5                 ✓ . . . ✓
- jsx
- lua                   ✓ ✓ ✓ ✓ ✓
- luadoc                ✓ . . . .
- luap                  ✓ . . . .
- markdown              ✓ . ✓ ✓ ✓
- markdown_inline       ✓ . . . ✓
- python                ✓ ✓ ✓ ✓ ✓
- query                 ✓ ✓ ✓ ✓ ✓
- regex                 ✓ . . . .
- ruby                  ✓ ✓ ✓ ✓ ✓
- toml                  ✓ ✓ ✓ ✓ ✓
- tsx                   ✓ ✓ ✓ ✓ ✓
- typescript            ✓ ✓ ✓ ✓ ✓
- vim                   ✓ ✓ ✓ . ✓
- vimdoc                ✓ . . . ✓
- yaml                  ✓ ✓ ✓ ✓ ✓
- zsh                   ✓ ✓ ✓ . ✓

  Legend: H[ighlights], L[ocals], F[olds], I[ndents], In[J]ections ~

Output of nvim --version

nvim --version
NVIM v0.12.0-dev-2027+g025c0c34ce
Build type: RelWithDebInfo
LuaJIT 2.1.1767980792
Run "nvim -V1 -v" for more info

Additional context

No response

Activity

  1. added theissue type on Jan 15, 2026
  2. added
    indentIssues or PRs about indentation queries or module
    on Jan 15, 2026
  3. Hook25 commented on Feb 3, 2026

    @Hook25

    In order to mitigate this (I've faced this myself) I had to turn off

    - vim.opt.smartindent = true
    

    This "solves" the issue although it leaves you without a lot of nice to have autoindentations.

  4. Dehta-Hun commented on Feb 6, 2026

    @Dehta-Hun
    Author

    In order to mitigate this (I've faced this myself) I had to turn off

    - vim.opt.smartindent = true
    

    This "solves" the issue although it leaves you without a lot of nice to have autoindentations.

    Thanks for work around!
    I don't encounter those kind of stuff often so setting it globaly - mehhh
    But when I did it drives me crazy. will try when happens next

  5. dmmqz commented on Feb 7, 2026

    @dmmqz

    This also happens with [ or (, even inside comments.

  6. lucario387 commented on Feb 8, 2026

    @lucario387
    Member

    indent is using syntax's and not treesitter's indent

    add vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" to better resolve the issue

  7. Hook25 commented on Feb 11, 2026

    @Hook25

    Note that for some reason I had both vim.bo.indentexpr = ... and vim.opt.smartindent = true. Removing the latter did fix the indentation issue I was having, though now sometimes the automated indentation seems a bit off sometimes

  8. korex-f commented on Mar 30, 2026

    @korex-f

    Unable to reproduce on NVIM v0.11.6 with the latest nvim-treesitter. Could this be specific to nightly builds?

  9. dmmqz commented on Mar 31, 2026

    @dmmqz

    It still happens for me on v0.11.7 @idrisakorede

  10. tianqiii commented on Apr 3, 2026

    @tianqiii

    btw this interesting issue appear in cpp when lambda expression too long in new line
    Image
    press o to insert new line here, then:

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    indentIssues or PRs about indentation queries or module

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions