Mosiah 2:36-37 says, in part, that “… if ye should transgress and go contrary to that which has been spoken, that ye do withdraw yourselves from the Spirit of the Lord … that the man that doeth this, the same cometh out in open rebellion against God; therefore he listeth to obey the evil spirit, and becometh an enemy to all righteousness; therefore, the Lord has no place in him, for he dwelleth not in unholy temples.”
The active words that are central to this verse are, “if ye should transgress and go contrary to that which has been spoken”. Transgression is what drives the Spirit away (a sin of omission can also be a sin of commission, and both are transgressions…).
So, to choose to act (or possibly not act [sin of omission…]) contrary to the Lord’s Will is to lose the Spirit which is sin. Why else would the Spirit withdraw from you? You are unclean…
Stay on the strait & narrow path, though, and be clean.
If you start on the strait and narrow, you are clean, and you have the Holy Ghost and Spirit of Christ to guide you and make good choices—now just never step off the path—and stay true till the end!
Any and every time you are tempted to leave the path or act contrary to that which you’ve been commanded to do, the Spirit of Christ and the Holy Ghost will remind you of what Christ would have you do and the enabling power of the Atonement of Jesus Christ will strengthen you so that you can stay on the path of righteousness.
JPS