In a strong city.--Some see a reference to David's adventures at Ziklag or Keilah; others to Jeremiah's in Jerusalem (Jeremiah 38). It is, however, better to regard it merely as a general image of the Divine protection.
for he hath showed me his marvellous kindness in a strong city; either in the city Keilah, so Jarchi; a city which had gates and bars, where Saul thought he had David safe, and he could not escape his hands; but notwithstanding that, and though the inhabitants of that place intended to deliver him up, yet he was marvellously saved; as he also was from the Ziphites; and when Saul and his army had encompassed him about, by a surprising incident, a messenger coming to Saul just as he was about to seize him, informing him that the Philistines had invaded the land, 1 Samuel 23:7. Or the city of Jerusalem, which was fortified both by nature and art, whither he was brought and placed as king, and enjoyed rest from all his enemies round about him, 2 Samuel 5:6. Or this may spiritually design the church of God, which is called a strong city, being built on Christ the Rock, and having salvation for walls and bulwarks, Isaiah 26:1, where the Lord displays his banner of love, makes discoveries of his marvellous kindness, and commands his blessing for evermore. Some render it "as in a strong city" (g), and take the sense to be, that he was safe, through the kindness of God showed to him in the salvation of him, as if he was in a fortified city (h), and this was marvellous in his eyes, as every instance of providential goodness is to the people of God; especially his lovingkindness showed in spiritual things, in choosing them in Christ, saving them by him, regenerating them by his Spirit, and taking them into his family; which love is free and sovereign, distinguishing, unchangeable, from everlasting to everlasting; and so wonderful and astonishing; and which was hid in God until revealed; and sometimes the manifestations of it are withdrawn, and then it is showed again, and fresh discoveries of it are made, and effects of it applied, and the blessings of it bestowed, which occasion thankfulness.
(g) "ut in civitate munita", Junius & Tremellius, Piscator; Michaelis. (h) Aben Ezra, Kimchi, & Ben Melech in loc.