Skip to content

Commit d5379f8

Browse files
author
Venkata Subramani Renduchintala
committed
fix(bigfile): replace abandoned bigfile.nvim with native BufReadPre autocmd
bigfile.nvim (LunarVim) is unmaintained since 2023 and calls vim.validate{<table>} which is deprecated and removed in Nvim 1.0. Replace with a plain autocmd in lua/autocmds.lua that replicates every feature: swapfile/undo/fold opts, matchparen, LSP block, treesitter stop, illuminate, ibl and deferred syntax/filetype clear.
1 parent c4f4440 commit d5379f8

4 files changed

Lines changed: 42 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,6 @@ See [`test/README.md`](test/README.md) for the full test suite documentation —
242242
- **[nvim-colorizer](https://github.com/norcalli/nvim-colorizer.lua)** — inline color preview for hex codes and CSS colors
243243
- **[undotree](https://github.com/mbbill/undotree)** — visual undo history tree
244244
- **[project.nvim](https://github.com/ahmedkhalf/project.nvim)** — automatic project root detection and project switching
245-
- **[bigfile.nvim](https://github.com/LunarVim/bigfile.nvim)** — disables heavy features for large files to maintain performance
245+
- **Large file handler** — native `BufReadPre` autocmd disables LSP, treesitter, syntax, illuminate and swapfile for files larger than 2 MiB
246246
- **[neoscroll.nvim](https://github.com/karb94/neoscroll.nvim)** — smooth scrolling animations
247247
- **[vim-startify](https://github.com/mhinz/vim-startify)** — start screen with recent files and sessions

lua/autocmds.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
})

lua/plugins/configs/bigfile.lua

Lines changed: 0 additions & 21 deletions
This file was deleted.

lua/plugins/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ local plugins = {
7171
require("plugins.configs.comment"),
7272
require("plugins.configs.flash"),
7373
require("plugins.configs.todo"),
74-
require("plugins.configs.bigfile"),
7574
require("plugins.configs.splitjoin"), -- Quick split or join of lists
7675
"mg979/vim-visual-multi",
7776

0 commit comments

Comments
 (0)