Finally, brethren, whatsoever things are true, whatsoever things are honest, whatsoever things are just, whatsoever things are pure, whatsoever things are lovely, whatsoever things are of good report; if there be any virtue, and if there be any praise, think on these things. —Philippians 4:8
You can probably look back right now and see a time where you opened the door in your mind and let the devil in—where you did not submit to God, where you did not resist the devil; therefore, he did not flee.
When you are rejoicing, the devil cannot get in your mind. When you are shouting, he cannot get in your body. When you are praising God and thanking Him for His goodness and mercy, the devil has no access to your life.
Build up your spirit by praying in the Holy Ghost. Renew your mind with the Word of God, and fill your mouth with His praises. Hang out a "NO VACANCY" sign for the devil, and when he tries to enter in, slam the door by lifting up your voice in praise and thanksgiving.
Strive after Jesus Christ's excellence and perfection. If you are tempted to think thoughts beneath what is true, just, pure, lovely, and virtuous, then stop thinking and start meditating on His Word. Replace every worldly thought with His Word.
Jesus, fill my mind with thoughts that
are true, honest, just, pure, lovely,
excellent, and virtuous. Amen.