Our teacher, the Beit Yosef, wrote in section 7: "One whose ship set sail at sea—he may walk through all of it, since he spent the Shabbat within the airspace of partitions. And if the walls of the ship were breached on Shabbat, if it is moving—he may walk through all of it, and if it is stationary—he may walk within it only four amot." Thus far his words. And behold, the Rambam did not mention this law at all, since there is no techumin above ten tefachim, and the Tur mentioned it, because he ruled in the previous siman that there is techumin above ten. But our teacher, the Beit Yosef, who ruled there that there is no techumin above ten, did not need this at all, and why when it is stationary may he walk within it only four amot? However, his intention is this: that he entered it on the eve of Shabbat, but it traveled several times at less than ten tefachim, or that he went out twice to the dry land, and consequently his law is like one who went outside the techum and is not considered as one under duress; therefore, when the walls are intact—he may walk through all of it, since he spent the Shabbat within the airspace of partitions while it was still day. But if he went to another ship or to a fenced area, since he did not spend the Shabbat within the airspace of the partitions while it was still day—he has only four amot. And when the walls of the ship were breached while it is stationary—consequently his law is like one who went outside the techum, who has only four amot. But when it is moving—it is permitted to walk through all of it, because with every single leap it is more than four amot, and the ship is constantly taking him from these four amot and placing him into another four. (Gemara 42b: "Rabbi Zira said since the ship takes him etc." see there, and see Magen Avraham subsection 7 and his words require great scrutiny, and delve into this)
כתב רבינו הב"י בסעיף ז': "מי שהפליגה ספינתו בים - מהלך את כולה, הואיל ושבת באויר מחיצות. ואם נפחתו דופני ספינה בשבת, אם היא מהלכת - מהלך את כולה, ואם היא עומדת - אינו מהלך בה אלא ד' אמות" עכ"ל. והנה הרמב"ם לא הזכיר כלל דין זה, כיון דאין תחומין למעלה מעשרה, והטור הזכיר, לפי שפסק בסימן הקודם דיש תחומין למעלה מעשרה. אבל רבינו הב"י שפסק שם דאין תחומין למעלה מי', לא היה צריך כלל לזה, ולמה כשהיא עומדת אינו מהלך בה אלא ד' אמות. אך כוונתו כן הוא, שנכנס בה מערב שבת, אך שהלכה כמה פעמים בפחות מעשרה, או שיצא שני פעמים ליבשה, וממילא דדינו כיוצא חוץ לתחום ולא נחשב כאנוס, ולפיכך כשהדפנות קיימות - מהלך את כולה, כיון ששבת באויר מחיצות מבעוד יום. אבל אם הלך לספינה אחרת או למקום המוקף, כיון שלא שבת באויר המחיצות מבעוד יום - אין לו אלא ד' אמות. וכשנפחתו דופני הספינה כשעומדת - ממילא דדינו כיצא חוץ לתחום, שאין לו אלא ד' אמות. אבל כשהיא מהלכת - מותר לילך את כולה, משום דבכל קפיצה וקפיצה היא יותר מד' אמות, ולעולם הספינה נוטלתו מד' אמות אלו ונתנתו לד' אחרים. (גמרא מ"ב: "ר' זירא אמר הואיל וספינה נוטלתו וכו'" ע"ש, ועיין מג"א סק"ז ודבריו צע"ג ודו"ק)