vegabook
Neovim indentation bug with more than one |> on a line (keeps wrongly adding another indentation)
I’m using Neovim with an nvim-treesitter plugin for elixir configured as follows:
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "python", "c", "lua", "vim", "vimdoc",
"query", "erlang", "heex", "eex", "elixir", "javascript", "html" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
},
So basically elixir is in there. But as you can see from this short asciinema quite often when I add another pipe |> on a line where it already exists, the whole line gets indented more, which obviously I don’t want.
There are some other “bugs” (?) where it will indent a pipe sometimes wrongly by two places under a variable, or will sometimes completely unindent a line with pipes in it.
Has anyone experienced this and is there a fix? Any ideas on which neovim plugin combinations work best? For guide my whole init.lua is here
Most Liked
josh.nz
I noticed a bunch of indentation issues when I briefly tested it out, esp around case → indenting and multi-line list construction. I’ve mostly been sucking into configuring Neovim, rather than using it, to date.
I did try playing around with a Treesitter query at one stage and while I know little about this, it seemed like Treesitter just didn’t have enough information to correctly indent code in all situations.
FWIW, I’m also noticing issues with Treesitter based Lua indenting, even on basic indenting situations.
I haven’t yet had a chance to come back to investigate this further (ref my comment about config :).
I have these notes in my Treesitter config:
highlight = {
enable = true,
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
-- If you are experiencing weird indenting issues, add the language to
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
additional_vim_regex_highlighting = { "ruby", "elixir" },
},
indent = {
enable = true,
disable = { "ruby", "elixir" },
},
This came from kickstart.nvim. I added the elixir entries, but haven’t tried it out yet, so don’t know if this helps or makes things worse. I suspect it will makes things worse, since I don’t see any built in Elixir syntax file.
I will also add that I’m not using the elixir-tools plugin. A quick scan of that doesn’t suggest it would help with indentation.
Finally, I will add make sure you’re using 0.10.0. There were changes to the Elixir ftplugin between 0.9.0 and 0.10.0 that do help. If you can’t upgrade, you can try patching your local file. Check here for the latest file content.
What I was doing when I briefly tested Elixir code, was to just periodically run vim.lsp.buf.format({ async = true }). It wasn’t ideal, but worked.







