וַיְהִ֕י כִּי־יָשַׁ֥ב הַמֶּ֖לֶךְ בְּבֵית֑וֹ וַיהוָ֛ה הֵנִֽיחַ־ל֥וֹ מִסָּבִ֖יב מִכָּל־אֹיְבָֽיו׃
И было, когда царь жил в своем доме, и Господь дал ему покой от всех его врагов вокруг,
Megillah
Vayehi when Shmuel was old (I Samuel 8:1) — then, his sons walked not in his ways. And David had [vayehi] great success in all his ways (I Samuel 18:14) — then, And Saul had enmity with David. Vayehi when the king dwelt in his house (II Samuel 7:1) — then, Nevertheless you shall not build the house.
Sanhedrin
And so it says about David “And it came to pass, when the king dwelt in his house, and the Lord had given him rest round about from all his enemies,” and it is further written “That the king said unto Nathan the prophet; ‘See now, I dwell in a house of cedar, but the ark of God dwells within the curtains.’” (Shmuel II 7:1-2)