How to change file permission from within vi

前端 未结 7 1807
庸人自扰
庸人自扰 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:29

    If you have the rights to write to the file, then you can just use exclamation mark to force it:

    :w!
    

    If you don't have the rights and need to change user, but still want to write to the file, sometimes you may go for something like

    :w !sudo tee %
    

提交回复
热议问题