LDIM determines the maximum number of reference-energies and l-quantum numbers
(i.e. pairs) for the non-local projection operators,
and LMDIM the maximum number of
reference-energies and lm-quantum numbers (i.e. triplets).

For conventional norm conserving pseudopotentials the number of
reference-energies per l-quantum number is one. The local pseudopotential
is usually the d-pseudopotential.
Therefore, non-local projection operators
for s and p are included in the pseudopotential file POTCAR
and LDIM should be 2 and LMDIM 4=1+3
(i.e. 1s and 3p projector).
The OUTCAR file contains information about the necessary setting.
At the startup of VASP the pseudopotential are read in
and information about the progress is written out:

The explicit formula for LDIM2 should not be changed and is correct, unless
the program is linked with us2.f instead of us.f. In principle
The module us2.f performs
the same tasks as us.f but allows a better optimization of
the augmentation charges. Nevertheless the pseudopotential generation program
does not support this improved optimization at the moment, therefore, there
is no reason to use us2.f.

The same holds for LMYDIM, as long as you use the module us.f simply set
LMYDIM to 9=1+3+5.