在vim中保存read-only文件

用 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文件)