简体   繁体   中英

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?

You can use:

:w !sudo tee %

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM