Repository: neovim/neovim
File: runtime/lua/vim/_defaults.lua (Lua)

Code before:
        -- Reset attributes first, as other code may have set attributes.
        io.stdout:write(string.format('\027[0m\027[48;2;%d;%d;%dm%s', r, g, b, decrqss))

        timer:start(1000, 0, function()
          -- Delete the autocommand if no response was received
          vim.schedule(function()
            -- Suppress error if autocommand has already been deleted
            pcall(vim.api.nvim_del_autocmd, id)
          end)

          if not timer:is_closing() then
            timer:close()
          end
        end)
      end
    end
  end

  vim.api.nvim_create_autocmd('VimEnter', {
    group = vim.api.nvim_create_augroup('nvim.find_exrc', {}),
    desc = 'Find project-local configuration',
    callback = function()
      if vim.o.exrc then
        local paths = vim.fs.find(
          { '.nvim.lua', '.nvimrc', '.exrc' },
          { type = 'file', upward = true }
        )
        if #paths > 0 then
          local trusted = vim.secure.read(paths[1])
          if type(trusted) == 'string' then
            loadstring(trusted)()
          end
        end
      end
    end
  })
end

--- Default options
do
  --- Default 'grepprg' to ripgrep if available.
  if vim.fn.executable('rg') == 1 then
    -- Use -uu to make ripgrep not check ignore files/skip dot-files
    vim.o.grepprg = 'rg --vimgrep -uu '
    vim.o.grepformat = '%f:%l:%c:%m'
  end
end


Review comment (suggestion):
`.nvimrc` and `.exrc` aren't Lua files, so loadstring won't work with these.

I think it's fine to only support this for `.nvim.lua`, at least for now. As long as that caveat is well-documented.

Code after:
        -- Reset attributes first, as other code may have set attributes.
        io.stdout:write(string.format('\027[0m\027[48;2;%d;%d;%dm%s', r, g, b, decrqss))

        timer:start(1000, 0, function()
          -- Delete the autocommand if no response was received
          vim.schedule(function()
            -- Suppress error if autocommand has already been deleted
            pcall(vim.api.nvim_del_autocmd, id)
          end)

          if not timer:is_closing() then
            timer:close()
          end
        end)
      end
    end
  end

  vim.api.nvim_create_autocmd('VimEnter', {
    group = vim.api.nvim_create_augroup('nvim.find_exrc', {}),
    desc = 'Find project-local configuration',
    callback = function()
      if vim.o.exrc then
        local files = vim.fs.find(
          { '.nvim.lua', '.nvimrc', '.exrc' },
          { type = 'file', upward = true, limit = math.huge }
        )
        for _, file in ipairs(files) do
          local trusted = vim.secure.read(file) --[[@as string|nil]]
          if trusted then
            if vim.endswith(file, '.lua') then
              loadstring(trusted)()
            else
              vim.api.nvim_exec2(trusted, {})
            end
          end
        end
      end
    end,
  })
end

--- Default options
do
  --- Default 'grepprg' to ripgrep if available.
  if vim.fn.executable('rg') == 1 then
    -- Use -uu to make ripgrep not check ignore files/skip dot-files
    vim.o.grepprg = 'rg --vimgrep -uu '
    vim.o.grepformat = '%f:%l:%c:%m'
  end
end