@@ -61,3 +61,44 @@ vim.api.nvim_create_autocmd("FileType", {
6161 vim .opt_local .formatoptions :remove { " t" , " c" , " a" , " r" , " o" }
6262 end ,
6363})
64+
65+ -- Large file handler: disable heavy features for files > 2 MiB
66+ vim .api .nvim_create_autocmd (" BufReadPre" , {
67+ callback = function (args )
68+ local buf = args .buf
69+ local ok , stat = pcall (vim .uv .fs_stat , vim .api .nvim_buf_get_name (buf ))
70+ if not (ok and stat and stat .size > 2 * 1024 * 1024 ) then
71+ return
72+ end
73+
74+ vim .opt_local .swapfile = false
75+ vim .opt_local .foldmethod = " manual"
76+ vim .opt_local .undolevels = - 1
77+ vim .opt_local .undoreload = 0
78+ vim .opt_local .list = false
79+
80+ if vim .fn .exists (" :DoMatchParen" ) == 2 then
81+ vim .cmd (" NoMatchParen" )
82+ end
83+
84+ vim .api .nvim_create_autocmd (" LspAttach" , {
85+ buffer = buf ,
86+ callback = function (lsp_args )
87+ vim .schedule (function ()
88+ vim .lsp .buf_detach_client (buf , lsp_args .data .client_id )
89+ end )
90+ end ,
91+ })
92+
93+ pcall (vim .treesitter .stop , buf )
94+ pcall (function () require (" illuminate.engine" ).stop_buf (buf ) end )
95+ pcall (function () require (" ibl" ).setup_buffer (buf , { enabled = false }) end )
96+
97+ vim .schedule (function ()
98+ if vim .api .nvim_buf_is_valid (buf ) then
99+ vim .bo [buf ].syntax = " OFF"
100+ vim .bo [buf ].filetype = " "
101+ end
102+ end )
103+ end ,
104+ })
0 commit comments