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!
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
: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.