Resolving to abandon a sin and intending to fast if one breaks that resolve
Question
Zayd keeps committing a certain major sin. He tries very hard to be rid of this sin; he repents and firmly resolves that he will not do it again, but the sin still occurs from him. So he devised a measure: whenever this sin occurs from him, he will fast for a week, so that the soul that commands to evil (nafs ammara) dies through fasting. But the sin occurred from him again, so he fasted for a week.
Answer
If he merely thought it in his heart and did not make it binding upon himself by way of a vow (nadhr) or an oath (yamin), then keeping such fasts is not binding upon him. However, abandoning sins, repenting, and asking Allah Most High for help to remain firm in repentance is necessary; and when repenting there should be a firm pledge that he will not do it in future.
Source: Fatawa Mahmudiyya
Preview. The full text opens with JavaScript enabled.