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

Code before:
  do
    local function on_diagnostics_change()
      local bufnr = vim.api.nvim_get_current_buf()

      local severity = vim.diagnostic.severity

      local result = {}
      local count = vim.diagnostic.count(bufnr)
      local errors = count[severity.ERROR] or 0
      if errors > 0 then
        table.insert(result, 'e:' .. errors)
      end
      local warnings = count[severity.WARN] or 0
      if warnings > 0 then
        table.insert(result, 'w:' .. warnings)
      end
      local infos = count[severity.INFO] or 0
      if infos > 0 then
        table.insert(result, 'i:' .. infos)
      end
      local hints = count[severity.HINT] or 0
      if hints > 0 then
        table.insert(result, 'h:' .. hints)
      end

      local result_str = table.concat(result, ' ')

      vim.b[bufnr].buffer_diagnostics = result_str

      vim.cmd.redrawstatus()
    end
    local group = vim.api.nvim_create_augroup('nvim.statusline.diagnostics', {})
    vim.api.nvim_create_autocmd('DiagnosticChanged', {
      desc = 'Update buffer diagnostics in the statusline',
      group = group,
      callback = on_diagnostics_change,
    })

    vim.api.nvim_create_autocmd('OptionSet', {
      pattern = 'statusline',
      group = vim.api.nvim_create_augroup('nvim.statusline', {}),
      callback = function()
        local value = vim.o.statusline
        vim.api.nvim_clear_autocmds({ group = group })
        if value == nil or value == '' then
          vim.api.nvim_create_autocmd('DiagnosticChanged', {
            desc = 'Update buffer diagnostics in the statusline',
            group = group,
            callback = on_diagnostics_change,
          })
          on_diagnostics_change()

Review comment (suggestion):
```suggestion
      local counts = vim.diagnostic.count(0)

      local user_signs = vim.tbl_get(vim.diagnostic.config(), 'signs', 'text') or {}
      local signs = vim.tbl_extend('keep', user_signs, { 'E', 'W', 'I', 'H' })

      local result_str = vim.iter(pairs(counts)):map(function(severity, count)
        return ('%s:%s'):format(signs[severity], count)
      end):join(' ')
```

Code after:
            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.exrc', {}),
    desc = 'Find exrc files in parent directories',
    callback = function()
      if not vim.o.exrc then
        return
      end
      local files = vim.fs.find({ '.nvim.lua', '.nvimrc', '.exrc' }, {
        type = 'file',
        upward = true,
        limit = math.huge,
        -- exrc in cwd already handled from C, thus start in parent directory.
        path = vim.fs.dirname((vim.uv.cwd())),
      })
      for _, file in ipairs(files) do
        local trusted = vim.secure.read(file) --[[@as string|nil]]
        if trusted then
          if vim.endswith(file, '.lua') then
            assert(loadstring(trusted, '@' .. file))()
          else
            vim.api.nvim_exec2(trusted, {})
          end
        end
        -- If the user unset 'exrc' in the current exrc then stop searching
        if not vim.o.exrc then
          return
        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