David's prayer in a place of danger. The title records that David had fled to a cave to find refuge from Saul (1 Sam 22; 24).
v1-3: David had found a place of apparent safety. But his refuge was truly in God. Only in God is there mercy. His confidence was that God would intervene, sending His love and faithfulness, by preserving David, and by rebuking those who sought to kill him.
v4: David felt alone; he was certainly out-numbered. Those who pursued him had set their hearts on his destruction.
v5: David's thoughts rebound from his pursuers to God. The works of God bring glory to His name.
v6: Back to his pursuers; they spread a net, they dug a pit, to trap David. His confidence was that God would turn their schemes upon themselves. One example was that Saul had earlier tried to have David killed at the hands of the Philistines (1 Sam 18.17), but Saul himself died at their hands.
v7-8: David was truly a man of faith; he trusted in God, finding his own heart "steadfast." He would therefore sing in praise to God. There is an exuberance here; Ps 43.4; 81.1-2; the Psalmist often brings noisy praise to God.
v9-10: The themes of David's songs were God's love and faithfulness (v3 also). The message of God is to be declared amongst His people, but far beyond, to all the nations. In Christ we see the fulfilment of this.
v11: Repeated from v5; the true believer is happy that glory goes to God.