I’m normally a straight vim user (just out of habit, no particular preference) and I’m giving neovim a spin. So far I like it but…

For the love of all that’s holy, how do I disable automatic indentation?

I have noautoindent set, nosmartindent set, filetype indent off, but neovim keeps inserting indentations. The only thing that works is setting paste on, but that’s not the right solution to this problem.

Please help. This is driving me nuts!

  • Oscar
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    5 months ago

    Try running this: :set indentexpr= and then :set noautoindent. Without any config file, this works for me while in a makefile that looks like this:

    foo: foo.c bar.h
            $(CC) $< -o $@
    

    The indentexpr option is set by filetype, but disabling filetype indent after already opening a makefile is too late, it would need to happen before opening it (in either a config file or directly after running nvim without any file specified).

    However, indentexpr seems to only control the automatic indentation when hitting enter at the target line, but not within the recipe for it. To fix that I also had to disable autoindent.

    • ExtremeDullard@lemmy.sdf.orgOP
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      5 months ago

      Okay so…

      I reinstalled Neovim 11 from scratch. ~/.config/nvim/ is empty:

      • I start “nvim Makefile”, type “test:<ENTER”: Neovim inserts a tab.
      • I start “nvim Makefile”, type “:se noautoindent” (or “:se noai”) then “test:<ENTER>”: Neovim inserts a tab - i.e. Neovim ignores noautoindent
      • I start “nvim Makefile”, type “:se indentexpr=” then “test:<ENTER>”: Neovim does NOT insert a tab: that works!
      • I put “se indentexpr=” in ~/.config/nvim/init.vim, start “nvim Makefile”, type “test:<ENTER”: Neovim inserts a tab - i.e. it ignores the statement in init.vim. But it doesn’t ignore other statements in init.vim: if I put “se bg=light” in it for instance, the background does indeed show up as light.

      So it seems the crux of the issue is that init.vim isn’t parsed properly.

      EDIT: but putting “filetype indent off” in ~/config/nvim/init.vim seems to do the trick. Thanks for the hint! This is a lot more complicated than it needs to be 🙂

      EDIT #2: “:syntax off” doesn’t turn off the syntax either. Well, I’ve had enough. Back to plain old vim…

      • Oscar
        link
        fedilink
        English
        arrow-up
        1
        ·
        5 months ago

        Oof, that’s annoying.

        Weird that :syntax off doesn’t work, from a small test it seems to do the trick for me. But I guess as long as vim works there’s no need to replace it 🙂

        • ExtremeDullard@lemmy.sdf.orgOP
          link
          fedilink
          arrow-up
          2
          ·
          5 months ago

          Well I’ve only given Neovim a spin for a few hours, but it’s been nothing but an exercise in frustration. Yeah syntax off works in vanilla nvim, but it’s replaced by treesitter commands if treesitter is enabled. And treesitter is really, really invasive and aggressive when it comes to highlighting and transparently rewriting what’s on the screen.

          So basically, without treesitter, it’s like vim, only more annoying to configure because init.lua is wildly inconsistent. With treesitter, it breaks my workflow at best (but I suppose I could get used to it) and it silently modifies what I see on the screen vs what I’m actually editing at worst, which is a hard no-no for me.

          I think maybe if I configured treesitter from the ground up, I could manage to make it leave my text alone, keep the regex-based syntax highlighting which suits me just fine, and only make treesitter suggest things - which is the only feature I wanted to try Neovim for really. But it’s just not worth the incredimazing complication. I’ve survived just fine without smart hinting from vi for decades, so I can easily do without it.

          But hey, thanks man 🙂