You are not logged in.

#1 2025-03-22 01:53:30

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,168

[solved] How to disable tree-sitter for TeX/LaTeX in Neovim?

I am trying to experiment with Neovim but have run into a problem I don't entirely understand, let alone have a clue how to solve.

I like VimTeX, so, in adapting my configuration, I tried to work through the various recommendations included in VimTeX's help. In particular, the recommendation is to disable tree-sitter for files handled by VimTeX. The docs recommend the following snippet:

require 'nvim-treesitter.configs'.setup {
  ignore_install = { "latex" },
  -- more stuff here
}

Since I've been trying to learn Lua and had already translated most of my `.vimrc` into Lua, I (eventually) tried:

require('nvim-treesitter.configs').setup = {
  ignore_install = { "latex" },
}

But this is obviously not right:

Error detected while processing /home/<username>/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/cfrees/.config/nvim/init.lua:140: module 'nvim-treesitter.configs' not found:
        no field package.preload['nvim-treesitter.configs']
        no file './nvim-treesitter/configs.lua'
        no file '/usr/share/luajit-2.1/nvim-treesitter/configs.lua'
        no file '/usr/local/share/lua/5.1/nvim-treesitter/configs.lua'
        no file '/usr/local/share/lua/5.1/nvim-treesitter/configs/init.lua'
        no file '/usr/share/lua/5.1/nvim-treesitter/configs.lua'
        no file '/usr/share/lua/5.1/nvim-treesitter/configs/init.lua'
        no file './nvim-treesitter/configs.so'
        no file '/usr/local/lib/lua/5.1/nvim-treesitter/configs.so'
        no file '/usr/lib/lua/5.1/nvim-treesitter/configs.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './nvim-treesitter.so'
        no file '/usr/local/lib/lua/5.1/nvim-treesitter.so'
        no file '/usr/lib/lua/5.1/nvim-treesitter.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        /home/<username>/.config/nvim/init.lua:140: in main chunk

If I run :checkhealth in neovim, the output for tree-sitter and VimTeX:

vim.treesitter: require("vim.treesitter.health").check()

- Nvim runtime ABI version: 15
- OK Parser: bash                 ABI: 14, path: /usr/share/nvim/runtime/parser/bash.so
- OK Parser: c                    ABI: 15, path: /usr/share/nvim/runtime/parser/c.so
- OK Parser: lua                  ABI: 14, path: /usr/share/nvim/runtime/parser/lua.so
- OK Parser: markdown             ABI: 14, path: /usr/share/nvim/runtime/parser/markdown.so
- OK Parser: markdown_inline      ABI: 14, path: /usr/share/nvim/runtime/parser/markdown_inline.so
- OK Parser: python               ABI: 14, path: /usr/share/nvim/runtime/parser/python.so
- OK Parser: query                ABI: 15, path: /usr/share/nvim/runtime/parser/query.so
- OK Parser: rust                 ABI: 14, path: /usr/share/nvim/runtime/parser/rust.so
- OK Parser: vim                  ABI: 14, path: /usr/share/nvim/runtime/parser/vim.so
- OK Parser: vimdoc               ABI: 14, path: /usr/share/nvim/runtime/parser/vimdoc.so

==============================================================================
vimtex: health#vimtex#check

VimTeX ~
- OK Vim version should have full support!
- OK General viewer should work properly!
- OK Compiler should work!

If I comment out the offending lines in init.lua, I don't get an error on startup (just from neovim without a file, say), but :healthcheck complains:

E5009: Invalid $VIMRUNTIME: /usr/share/nvim/runtime
Error executing lua: function health#vimtex#check[1]..vimtex#options#init[268]..<SNR>53_init_option[5]..vimtex#util#extend_recursive, line 7: Vim(if):E1206: Dictionary required for argument 1
stack traceback:
        [C]: in function 'call'
        /usr/share/nvim/runtime/lua/vim/health.lua:429: in function '_check'
        [string "<nvim>"]:1: in main chunk

This looks like a syntax error in Lua (?), but I'm not sure where it is referencing i.e. which file contains the error and which line. (I'm assuming the problem is not health.lua line 429. That's just where the error gets found. What do the hash symbols mean in this context? [As opposed to dots or slashes.])

I can't even figure out which part of the documentation I should be reading to understand what is going on. Obviously, there is no nvim-treesitter.configs  module, but is the problem that there should be or that the configuration snippet is wrong?

I'd really appreciate a pointer in some more constructive direction than a circle.

Last edited by cfr (2025-03-31 22:07:46)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#2 2025-03-31 22:07:18

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,168

Re: [solved] How to disable tree-sitter for TeX/LaTeX in Neovim?

This was a really stupid thing to miss, but I somehow got lost between 3 different lots of documentation and failed to register the difference between treesitter, included in Neovim, and nvim-treesitter, a plugin for Neovim. The instructions for disabling treesitter in VimTeX require nvim-treesitter.

So my current setup works (er, I think) and uses the lazy.vim plugin manager.

-- .config/nvim/lua/plugins/nvim-treesitter.lua
local spec = {
  "nvim-treesitter/nvim-treesitter",
  build = ":TSUpdate",
  config = function()
    require("nvim-treesitter.configs").setup {
      ensure_installed = {
        -- "bash",
        "latex",
        "lua",
        "vim",
        "vimdoc",
      },
      sync_install = false,
      auto_install = false,
      highlight = {
        enable = true,
        disable = { "latex" },
      },
      indent = {
        enable = true,
        disable = { "latex" },
      },
    }
  end,
}
return spec

Though I should probably enable auto- something or disable auto- something as this seems to get updates every two minutes or so.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB