The psalmist's confidence that the Lord would protect him was strong.
31:3-4 David believed God would free him from his present entangling problems because the Lord had promised to help the righteous in their afflictions.
31:5 David committed his life to God's care. He did so confidently because God had faithfully delivered him in the past and had proved true to His promises. The Lord Jesus prayed the first line of this prayer on the cross (Luke 23:46). We should also follow this example in our times of suffering (1 Pet. 4:19).
31:6 The opposite of trusting in Yahweh is putting confidence in an idol, a vain object of hope whatever that object might be.
31:7-8 Even though the psalmist had not yet experienced deliverance, he delighted in the loyal love of his God. God had not handed him over to his enemy so the prospects for the future were encouraging. Even though final deliverance was yet to come, David could praise God as he waited for it since he believed God would be faithful to His promises to help His afflicted. Paul and Silas sang praises to God in the Philippian jail with the same confidence (Acts 16:25).