1

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?

vico
  • 17,051
  • 45
  • 159
  • 315
  • 1
    `:w !sudo tee %` is the usual way to do this. The answer has been provided many a times before, where [How does the vim “write with sudo” trick work?](http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work) is one of the better ones. There's also the plugin [SudoEdit.vim](https://github.com/chrisbra/SudoEdit.vim). – timss Oct 27 '15 at 11:39
  • 3
    Possible duplicate of [Getting root permissions on a file inside of vi?](http://stackoverflow.com/questions/1005/getting-root-permissions-on-a-file-inside-of-vi) – timss Oct 27 '15 at 11:51

2 Answers2

4

You can use:

:w !sudo tee %

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

Community
  • 1
  • 1
Daniel Milde
  • 1,096
  • 1
  • 12
  • 15
0

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.

Community
  • 1
  • 1
rajuGT
  • 6,224
  • 2
  • 26
  • 44