This is an automated archive made by the Lemmit Bot.

The original was posted on /r/neovim by /u/shelper9527 on 2024-11-06 14:16:17+00:00.


i have a minimized json file that is only 80k, and when i open it in nvim (i am using lazyvim), it takes 10s to open it, i am able to open it immediately with --noplugin, i tried to disable features one by one and found the treesitter caues the issue, so i add the autocmd below, but it does not work… it still takes 10s to open the file, did i miss anything?

-- Define the maximum line length threshold
local max_line_length = 1000

-- Create an autocommand group for managing large files
local augroup = vim.api.nvim_create_augroup("PerformanceTweaksForLongLines", { clear = true })

-- Define the autocommand
vim.api.nvim_create_autocmd("BufWinEnter", {
  group = augroup,
  callback = function()
    local bufnr = vim.api.nvim_get_current_buf()

    -- Get the first line of the buffer
    local first_line = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or ""

    -- Check if the first line length exceeds the threshold
    if #first_line > max_line_length then
      -- Disable Treesitter
      vim.treesitter.stop(bufnr)

      -- Disable syntax highlighting
      vim.bo[bufnr].syntax = "off"

      -- Disable line wrapping for better performance
      vim.wo[bufnr].wrap = false
      vim.wo[bufnr].linebreak = false

      -- Disable relative and absolute line numbers
      vim.wo[bufnr].number = false
      vim.wo[bufnr].relativenumber = false

      -- Disable the cursor line and cursor column highlights
      vim.wo[bufnr].cursorline = false
      vim.wo[bufnr].cursorcolumn = false

      -- Disable fold column, which can also slow down large files
      vim.wo[bufnr].foldenable = false

      -- Disable sign column to avoid any gutter processing
      vim.wo[bufnr].signcolumn = "no"

      -- Notify the user that performance tweaks have been applied
      vim.notify("Performance tweaks applied due to long line exceeding " .. max_line_length .. " columns", vim.log.levels.WARN)
    end
  end,
})