發表文章

目前顯示的是有「VIM」標籤的文章

Linux作業系統_VIM權限異常_vim error E212: Can't open file for writing

圖片
過往自己練習通常root權限都用習慣了,要做任何事情都暢行無阻, 現在在公司組織內由於權限控管 我只能用一般帳號登入,開始遇到一些怪怪的問題。 近期在用vim要存檔時直接下:wq 會出現錯誤訊息 E212: Can't open file for writing 這時可以透過,來做存檔的問題排除。 : w ! sudo tee % 等同由外部 sudo 再使用 tee 將 stdin 寫入檔案, 因此檔案變更,Vim 發覺有資料變更,需要重新載入檔案內容。 :w:Vim 的標準檔案寫入 !:執行外部命令 sudo:權限提昇 tee:把 stdin 存到文件的程式 %:Vim 的暫存器,存目前編輯文件的路徑名稱 可以 :echo @% 查看,更多資訊可見下面: :echo @% " directory/name of file :echo expand('%:t') " name of file ('tail') :echo expand('%:p') " full path :echo expand('%:p:h') " directory containing file ('head') Ref: vim error E212: Can't open file for writing http://oscarguo.blogspot.com/2016/09/vim-error-e212-cant-open-file-for.html Vim 使用 tee 和 sudo 解決臨時權限不足的問題 https://blog.longwin.com.tw/2018/11/vim-tee-sudo-permission-file-write-2018/ vim 用 :w !sudo tee % 进行保存的终极奥义 https://www.cnblogs.com/ayanmw/p/12769655.html