Write to file using vim when sudo privileges needed

I have text in vim that I would like to save to pace where sudo privileges are needed. How to solve this when vim is started without sudo?


To put it in other words

Can I give sudo permission to already running process?

I don't think this is possible. I tried to find out if there is any way, but no. check this post.

Workaround :

You can use :sav <new/path/filename.extn> to save it some place where you have right permission (temporarily). Later open the vim process with super user permission this temporary saved file and save to the target destination using the above mentioned command.


You can use:

:w !sudo tee %

as explained here: How does the vim "write with sudo" trick work?

链接地址: http://www.djcxy.com/p/49588.html

上一篇: vims cmd开球到持续的python'看门狗'进程

下一篇: 当需要sudo权限时使用vim写入文件