Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

Vim 儲存檔案 & 關閉

Posted on 2022 年 6 月 20 日2022 年 6 月 20 日 By 日落 在〈Vim 儲存檔案 & 關閉〉中尚無留言

聽了某分享,聽到 :wq 和 ZZ 一樣都是儲存並關閉,和印象中的有些出入,所以直接 :h 查 vim 的說明。

:h wq

Write the current file and close the window. If this was the last edit-window Vim quits.
Writing fails when the file is read-only or the buffer does not have a name. Quitting fails when the last file in the argument list has not been edited.

:h ZZ

Write current file, if modified, and close the current window (same as “:x”). If there are several windows for the current file, only the current window is closed.

所以主要差異有:

  • :wq 不管檔案是否有變更、異動,都會在 vim 關閉之前寫入檔案;如果使用 ZZ 則僅在檔案內容有變更時才會寫檔,否則直接退出 vim。
  • :wq 後面可以加上參數。例如寫入後關閉,但是希望另存新檔時,可以使用 :wq new-file 來要求 vim 將內容寫入其他檔案。
Tags:Vim

文章導覽

Previous Post: 近期的鐵氟龍膠帶
Next Post: Vim 視窗管理工具

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


其他

關於我  (About me)

小額贊助

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.