Is there a rule for using gerunds and infinitives instead of memorizing the verbs? I mean when to use gerund or infinitive just by looking at the sentence.
There is no such rule. Each verb has its own rules for what sorts of complement clause it 'licenses', and it has little or nothing to do with semantics.
This is in fact a question which has had a lot of attention from linguists in the last fifteen or twenty years. Some general tendencies have been observed, such as the “Great Complement Shift”, the tendency over the past five or six hundred years for gerund complements to replace infinitive complements, or that gerunds tend to be preferred in ‘Backward-looking’ contexts and infinitives in ‘Forward-looking’ contexts.
But these are no more than statistical tendencies: they have no predictive value and cannot be relied on to determine what form should be used in any particular instance with any particular verb. I'm afraid the only sure guide is to consult actual contemporary usage for each verb.