聽了某分享,聽到 :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 將內容寫入其他檔案。