2021年1月12日 星期二

Vim 強制覆寫檔案的方式

使用 Vim 編輯檔案時,有時候會遇到權限不足或檔案為唯獨的狀況而造成我們的修改無法順利寫入,這邊提供一些方式來解決此類的問題。


Case 1 檔案為唯獨時強制儲存的方式

● 使用:w!強制覆寫

● 先用:set noreadonly,再下:w覆寫


Case 2 你有 sudo 的權限,但沒先用 sudo 開啟檔案

● 使用:w !sudo tee %




參考資料

[Stack Exchange] Using vim to force edit a file when you opened without permissions

訪客統計