2

I have my entire nvim setup written in vim script at ~/.config/nvim/init.vim, but tresitter on it's GitHub says

require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all" (the five listed parsers should always be installed)
  ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  -- List of parsers to ignore installing (for "all")
  ignore_install = { "javascript" },

  ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!

  highlight = {
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { "c", "rust" },
    -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
    disable = function(lang, buf)
        local max_filesize = 100 * 1024 -- 100 KB
        local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        if ok and stats and stats.size > max_filesize then
            return true
        end
    end,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

How and where do I put it in init.vim so I can tweak tresitter from text file (.vim or .lua)? I use vundle plugin manager.

1
  • 1
    @Friedrich thanks!
    – iago
    Commented Nov 3, 2023 at 15:41

1 Answer 1

2

The "standard" way is to:

  • Create a treesitter.lua file in ~/.config/nvim/lua/config
  • Copy the GitHub proposition in that file
  • Add the following line in init.vim:
lua require('config/treesitter')
7
  • 1
    I did everything as you said and got Error detected while processing /Users/vladyslav/dotfiles/nvim/init.vim: line 101: E5108: Error executing lua [string ":lua"]:1: module 'config/treesitter' not found: no field package.preload['config/treesitter'] no file './config/treesitter.lua' < I skipped some output to fit in comment> no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'require' [string ":lua"]:1: in main chunk Press ENTER or type command to continue Commented Jun 12, 2023 at 9:04
  • The ~/.config/nvim is a link to ~/dotfiles/nvim Commented Jun 12, 2023 at 9:06
  • You can find my init files and error photo at github.com/Dolfost/dotfiles/tree/lua/test/nvim Commented Jun 12, 2023 at 9:11
  • 1
    Is the treesitter.lua file in ~/.config/nvim/lua/config or for you in ~/dotfiles/nvim/lua/config? From the repository I have the impression that it is in ~/dotfiles/nvim/lua. Which is actually my mistake because I wrote that in the first version of my answer :-/ sorry for that. Commented Jun 12, 2023 at 9:20
  • 1
    Thanks for the feedback :-). Commented Jun 12, 2023 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.