vim出现“E212: Can't open file for writing”的处理办法

在使用vim 对文件或配置进行编辑的时候,在保存时发现当前用户没有写权限。又不想放弃当前编辑的内容,怎么办呢?

来自stackoverflow
“For some reason the file you are writing to cannot be created or overwritten.
The reason could be that you do not have permission to write in the directory
or the file name is not valid.

Vim has a builtin help system, I just quoted what it says to :h E212. You might want to edit the file as a superuser like sudo vim FILE. Or if you don't want to leave your existing vim session (and know have proper sudo rights), you can issue:

:w !sudo tee % > /dev/null

Which will save the file. ”

这样文件的所有者是root,依然没有写的权限。只需更改文件的所有者和组:

[sany@sanshui code]$  sudo chown 用户名:组名  文件名

当你用上述方法强制写的时候,会提示如下:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

【linux总是这么可爱大笑

转载于:https://www.cnblogs.com/zhangeamon/p/6552483.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值