Usually, it is possible to use both 「こと」 and 「の」 for nominalisation of verbs though 「の」is less formal than 「こと」.
However, only 「こと」 is used with the verb of decision and/or custom. i.e. You can say that 「することに決めた」or 「することにしている」 but not 「するのに決めた」 or 「するのにしている」.
Also, nominalisation before the end of sentences (i.e. before です)is also used 「こと」 instead of 「の」. i.e. You can say that 「私の仕事は日本語を教えることです」 but not 「私の仕事は日本語を教えるのです」.
On the other hand, you can use only 「の」 with the verb of perception. i.e. You can say that 「赤ちゃんが泣いているのが聞こえる」 but 「赤ちゃんが泣いていることが聞こえる」.
In this case, I think it is better to remember one by one when those verbs come across to you than try to think about the logic.