-- Stolen from https://github.com/folke/snacks.nvim/blob/main/lua/snacks/bigfile.lua local auto = require 'std.auto' local defaults = { size = 1.5 * 1024 * 1024, -- 1.5MB -- Enable or disable features when big file detected ---@param ctx {buf: number, ft:string} setup = function(ctx) vim.cmd([[NoMatchParen]]) vim.opt.shadafile = '' vim.schedule(function() vim.bo[ctx.buf].syntax = ctx.ft end) end, } vim.filetype.add({ pattern = { [".*"] = { function(path, buf) return vim.bo[buf] and vim.bo[buf].filetype ~= "bigfile" and path and vim.fn.getfsize(path) > defaults.size and "bigfile" or nil end, }, }, }) auto 'bigfile' { events = 'FileType', pattern = "bigfile", command = function(ev) local path = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(ev.buf), ":p:~:.") vim.notify(("Big file detected `%s`."):format(path) .. "\nSome Neovim features have been **disabled**.", vim.log.levels.WARN, { title = 'bigfile' }) vim.api.nvim_buf_call(ev.buf, function() defaults.setup({ buf = ev.buf, ft = vim.filetype.match({ buf = ev.buf }) or "", }) end) end, }