this post was submitted on 15 Jun 2024
16 points (94.4% liked)

Neovim

2169 readers
3 users here now

founded 1 year ago
MODERATORS
 

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!

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 3 points 5 months ago* (last edited 5 months ago) (12 children)

I'm not using anything at the moment.

My intention was to give naked Neovim a spin and make sure it performs how I like Vim to perform. Then once it covers what I consider the basics, I was planning on layering kickstart.nvim on top of it and customizing Kickstart to my odd tastes.

The problem being, my odd tastes include:

1/ ABSOLUTELY NO AUTOINDENT. I hate autoindent with a burning passion, in all circumstances

2/ Must work in an 80-column terminal, meaning no line numbers - or at least line numbers that can be disabled. I've survived 40 years without line numbers, I can go on without them a few more ๐Ÿ™‚

Right now I'm stuck at 1/ without even having installed Kickstart. I'm not installing it until I manage to disable autoindent. And I still haven't found out how to do that, so I'm back to vanilla Vim for now because I have work to do.

[โ€“] oscar 5 points 5 months ago* (last edited 5 months ago) (10 children)

Using a the ubuntu 24.04 docker image for testing, I was able to disable automatic indentation with this config in ~/.config/nvim/init.lua:

vim.cmd("filetype indent off")

If you prefer using vim syntax it would instead be the following in ~/.config/nvim/init.vim:

filetype indent off

Note: it seems this file is not loaded if a init.lua file is present in that directory

Edit to add: So the reason this is required is, similar to vim (so you may already be familiar with this), there are filetype-specific configurations loaded. These usually reside in /usr/share/nvim/runtime/<plugin/indent/syntax/etc>/<filetype>. You can configure what files to load using the :filetype command.

There's more info here: https://neovim.io/doc/user/filetype.html

Second edit: Also when filetype indent/plugin/syntax is on, it seems to be loaded after your user config, so it overrides it. You can investigate if your actual config was applied or not by running, for example, :set autoindent? or :set cindent?. If the values do not match your configuration, it was likely overridden by :filetype. This was the case for me.

[โ€“] ericjmorey 2 points 5 months ago (3 children)

What you describe seems to be what the user manual describes. OP did state "I have noautoindent set, nosmartindent set, filetype indent off" I have a hunch that they, comming from vim, used a .vim config file and didn't realize it wasn't loading because a .lua config file was already present in the folder. But this is just speculation.

[โ€“] oscar 3 points 5 months ago

Ah dang, you're right, I must have read it too quickly. Yeah then I also think it's something about not loading the config, it can be investigated by checking the runtime values like I described in my second edit.

load more comments (2 replies)
load more comments (8 replies)
load more comments (9 replies)