vico
vico

Reputation: 18191

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?

Upvotes: 1

Views: 5208

Answers (2)

Daniel Milde
Daniel Milde

Reputation: 1194

You can use:

:w !sudo tee %

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

Upvotes: 6

rajuGT
rajuGT

Reputation: 6404

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.

Upvotes: 0

Related Questions