The unhelpful answer, I'm afraid, is that you just have to learn set phrases and combinations of words. You need to read and listen to as much native speaker English as possible, until it becomes instinctive to you, and you know what forms sound right following particular verbs and phrases. Here are a couple of tips, though:
You always use an 'ing' form (gerund) after prepositions - of, with, from, by, through, on and so on. The only exception is 'to', which is usually - though not always - followed by the infinitive. This rule is an extremely good and very important rule that will help you a lot. I wish that more students knew it and took notice of it.
Modal verbs (can, must etc) are followed by the infinitive without 'to'. Some causative verbs, like 'make' and 'let' are also followed by the infinitive without 'to'. For example, 'Let me see'.
This is a more general idea, but it often works. Following verbs referring to plans, desires etc about the future, we
often use 'to' + infinitive - want, hope, decide, intend, need, plan, would like, for example, are all followed by 'to' + infinitive.