vim

Martynas Maciulevičius 2024-08-08T09:09:27.363749Z

Is there a way to open files in the background but also run all of the autocommands too? I tried to do this but I end up changing the buffer that I'd open normally and it also ends up not running the filetype check:

local function str_empty(s)
  -- omitted
end

-- 
function split_str(inputstr, sep)
  -- omitted
end

function scanGitFiles()
  output = vim.fn.system("git ls-files --cached --others --exclude-standard 2>/dev/null")
  if str_empty(output) then
    return
  end
  foundFiles = split_str(output, "\n")
  for _k, bufName in pairs(foundFiles) do
    vim.api.nvim_exec(":badd " .. bufName, false)
  end
  --vim.api.nvim_exec(":silent bufdo e", false)
  print("len: " .. #foundFiles)
end
My goal is to load every file so that they all would be added to the LSP server's cache. I don't understand why the file is loaded but autocommands aren't run. It lists all my buffers in the :ls as having no flags (no h flag) so it's weird that it gets to know about the buffer but no loading happens. And previously the edit call was not failing but it wasn't doing anything.