How to change file permission from within vi

前端 未结 7 1796
庸人自扰
庸人自扰 2021-02-02 09:58

I sometimes open a read-only file in vi, forgetting to do chmod +w before opening it. Is there way to change the file from within vi?

Something like !

相关标签:
7条回答
  • 2021-02-02 10:56

    After editing your file with vim, press "esc" and then ":". Then type the following command:

    w !sudo tee %
    

    Then press "Enter". Then type

    :q!
    

    to successfully exit from the editor.

    0 讨论(0)
提交回复
热议问题