From c5384e25f749129104e6f21af273d9ab7211b92c Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:04:49 -0500 Subject: [PATCH] Nvim: disable treesitter on large files --- .config/nvim/lua/config/lazy.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.config/nvim/lua/config/lazy.lua b/.config/nvim/lua/config/lazy.lua index 0da8934..c8c6abf 100644 --- a/.config/nvim/lua/config/lazy.lua +++ b/.config/nvim/lua/config/lazy.lua @@ -18,6 +18,22 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) +local function disable_plugins_for_large_files() + local max_filesize = 1024 * 1024 -- 1 MB + local filepath = vim.fn.expand("%:p") + local filesize = vim.fn.getfsize(filepath) + if filesize > max_filesize then + -- Disable treesitter + vim.cmd("TSBufDisable") + end +end + +-- Autocmd to check file size on BufRead +vim.api.nvim_create_autocmd("BufRead", { + callback = disable_plugins_for_large_files, + desc = "Disable heavy plugins for large files", +}) + require("lazy").setup({ root = lazy_home, spec = {