As a general rule, you use gerunds (-ing form) as the subject of a sentence:
Swimming is good for you.
After prepositions:
eg by writing, for writing, before writing,
and after certain verbs
eg I enjoy reading, I practise singing
Other verbs are followed by to + infinitive:
eg I want to eat, I decide to leave
A few verbs can take either form, depending on their meaning.
I suggest you look at a grammar book or website under the heading 'Gerunds and Infintitives', and spend some time studying it. Then if you have any specific questions, come back to us with some examples. Good luck!