  Cosmic gas makes up about 90% of baryonic matter in the Universe and H$_2$ is
the closest molecule to star formation. In this work we study cold neutral gas
and its H$_2$ component at different epochs, exploiting state-of-the-art
hydrodynamic simulations that include time-dependent atomic and molecular
non-equilibrium chemistry coupled to star formation, feedback effects,
different UV backgrounds presented in the recent literature and a number of
additional processes - such as gas self-shielding, H$_2$ dust grain catalysis,
photoelectric and cosmic-ray heating - occurring during structure formation
(ColdSIM). We find neutral-gas mass density parameters $ \Omega_{\rm neutral}
\simeq $10$^{-3}$ and increasing from lower to higher redshift, in agreement
with available HI data. Resulting H$_2$ fractions can be as high as $\sim $50%
at $z\sim $4-8, in line with the latest high-$z$ measurements. Albeit dependent
on the adopted UV background, derived $ \Omega_{\rm H_2} $ values agree with
observations up to $z\sim$7 and both HI and H$_2$ trends are better reproduced
by our non-equilibrium H$_2$-based star formation modelling. The predicted gas
depletion timescales decrease towards lower $z$, with H$_2$ depletion times
remaining below the Hubble time and comparable to the dynamical time at all
considered redshifts. This implies that non-equilibrium molecular cooling is
efficient at driving cold-gas collapse in a broad variety of environments and
since the very early cosmic epochs. In appendix, we show detailed analyses of
individual processes, as well as simple numerical parameterizations and fits to
account for them. Our findings suggest that, in addition to HI, non-equilibrium
H$_2$ observations are pivotal probes for assessing cold-gas abundances and the
role of UV background radiation - Abridged
