What is the difference between (verb)こと and (verb)の?

I see sentences like 映画を見るのが好きです but in other sentences, the way to nominalize verbs is with こと, as in 趣味は映画を見ることです.
When do you use one or the other?

Off the top of my head こと and の can most of the time be freely swapped without losing the meaning, but there are some cases where の cannot replace こと (and vice versa). Like in your second example only こと is correct, as の can’t be used at the end of the sentence with だ/です.

Maybe someone else can enlighten if there are some subtle nuances in cases where both can be used.

EDIT: Found a site explaining some of the exceptions: https://www.wasabi-jpn.com/japanese-grammar/nominalizers-koto-and-no/


To add, here’s a pretty detailed stack exchange on こと vs の.