The Tur wrote in the name of Rav Amram Gaon: "This which they are accustomed to say 'Vihi Noam' and the Kedusha de-Sidra with melody and with a pleasant lengthening at the conclusion of Shabbat—is so that Israel should linger in completing their orders, in order to lengthen for the wicked the time before returning to Gehenna, for at the conclusion of Shabbat the one appointed over the spirits cries out: Return to Gehenna, for Israel has already completed their orders." Thus far his words. And regarding 'Vihi Noam' he wrote another reason, because it is a psalm of blessing with which Moshe blessed Israel at the time they finished the work of the Mishkan, and on Sunday the work of the Mishkan was completed, as is taught in the Baraita of the Ten Crowns (Shabbat 87b), and therefore we say it as a sign of blessing for the six workdays coming toward us in peace. And it is customary to double the verse 'Orech Yamim etc.', and the Tur wrote that because through this the Name that emerges from it is completed, thus far his words, and we know nothing of this (see Magen Avraham). And according to its plain meaning, this verse is doubled wherever it is found, such as in the psalms of Shabbat and Yom Tov in Shacharit where they also double it. And perhaps from 'Vihi Noam' until after 'Orech Yamim' there are sixteen verses, and they double it as a sign for the number 'Tov'. And they begin with 'Ve-Atah Kadosh' and not with 'U-Va Le-Tzion Goel', for there is no redemption at night. And also not the verse 'Va-Ani Zot Beriti', for the primary engagement in Torah is by day, as it is brought in Eruvin (65a): 'We are day workers'. Furthermore, we wish to juxtapose the verses of 'Yoshev Be-Seter' to 'Ve-Atah Kadosh', meaning that because in this psalm it is explained how the Holy One, Blessed be He, protects us: 'A thousand shall fall at your side etc.', 'With long life etc.'—for this we sanctify His Name, may He be blessed. Therefore, when they do not say 'Vihi Noam'—they also do not say 'Ve-Atah Kadosh', and this is when a Yom Tov falls in the middle of the week, for there are not six workdays. Furthermore, Moshe said 'Vihi Noam' at the completion of the Mishkan, and then the Shekhinah rested, and this is 'And You are Holy, Who dwells amidst the praises of Israel' (Turei Zahav). And if the Yom Tov falls on the following Shabbat—they say 'Vihi Noam' and 'Ve-Atah Kadosh', for behold there are six workdays. And there are those who stammer regarding these customs, but the custom of Israel is Torah.
כתב הטור בשם רב עמרם גאון: "זה שנהגו לומר 'ויהי נועם' וקדושה דסדרא בנעימה ובאריכות נועם באפוקי שבתא - כדי שישתהו ישראל בהשלמת סדריהם, כדי להאריך לרשעים מלחזור לגיהנם, דבמוצאי שבת צועק הממונה על הרוחות: חזרו לגיהנם, שכבר השלימו ישראל את סדריהם" עכ"ל. ועל 'ויהי נועם' כתב עוד טעם, לפי שהוא מזמור של ברכה שבו בירך משה לישראל בשעה שסיימו מלאכת המשכן, וביום א' נשלמה מלאכת המשכן, כדתניא בברייתא דעשר עטרות (שבת פ"ז:), ולכן אנו אומרים לסימן ברכה על ששת ימי המעשה הבאים לקראתינו לשלום. ונוהגין לכפול פסוק 'אורך ימים וגו', והטור כתב לפי שעל ידי כן נשלם השם היוצא ממנו עכ"ל, ואין אתנו יודע עד מה (עיין מג"א). ולפי פשטותו הפסוק הזה בכל מקום שהוא כופלים אותו, כמו במזמורי שבת ויום טוב בשחרית שגם כן כופלים אותו. ואולי דמ'ויהי נועם' עד אחר 'אורך ימים' יש ט"ז פסוקים, וכופלים אותו לסימן מספר טו"ב. ומתחילין ב'ואתה קדוש' ולא ב'ובא לציון גואל', דאין גאולה בלילה. וגם לא פסוק 'ואני זאת בריתי', דעיקר עסק התורה הוא ביום, כדאיתא בעירובין (ס"ה.): 'אנן פועלי דיממא אנן'. ועוד דאנו רוצים להסמיך פסוקי 'יושב בסתר' ל'ואתה קדוש', כלומר משום שבמזמור זה מבואר איך הקב"ה שומר אותנו: 'יפול מצדך אלף וגו', 'אורך ימים וגו' - לזה אנו מקדישים שמו יתברך. ולכן כשאין אומרים 'ויהי נועם' - אין אומרים גם 'ואתה קדוש', וזהו כשחל יום טוב באמצע השבוע, דליכא ששת ימי המעשה. ועוד ד'ויהי נועם' אמר משה בסיום המשכן, ואז שרתה שכינה, וזהו 'ואתה קדוש יושב תהלות ישראל' (ט"ז). ואם חל היום טוב בשבת שאחר כך - אומרים 'ויהי נועם' 'ואתה קדוש', שהרי יש ששת ימי המעשה. ויש מגמגמים במנהגים אלו, אבל מנהג ישראל תורה.