美文网首页
在vim中保存read-only文件

在vim中保存read-only文件

作者: 江河湖海洋 | 来源:发表于2023-03-13 11:48 被阅读0次

    用 vim 打开没有写权限的文件而忘记用 sudo 时,文件变成 read-only,

        :w !sudo tee %
    

    :w : Write a file.可以将文件写入,文件仍然是只读模式,通过 :q! 退出
    !sudo : Call shell sudo command.
    tee : The output of the vi/vim write command is redirected using tee.
    % : Triggers the use of the current filename.


    图片.png

    然后输入 "L",
    回到编辑界面,再在命令模式下输入 :q 退出即可。

    相关文章

      网友评论

          本文标题:在vim中保存read-only文件

          本文链接:https://www.haomeiwen.com/subject/pydcrdtx.html