How to change file permission from within vi

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

    Have you tried

    !chmod +w %
    

    The % represents the current filename.

    You could also map a key to this like Ctrl-W.

    :map  :!chmod +w %
    

    Note that you type Ctrl-V Ctrl-M to get the

提交回复
热议问题