I would like to edit files like
C:\Widows\System32\Drivers\etc\hosts that need administrative privilege to be modified.
How can save the file on Windows if Vim has not been starter with administrator privileges?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
Some time ago I wrote a small utility xmove.
Basically, it saves stdin into temporary file and re-runs itself with elevated privileges. Finally, the second instance moves temporary file to the proper destination.
So this is supposed to do the trick:
:w !xmove % and then
set nomod. You can pull, build and check if it still works.
The straightforward solution would be
to save the file to some other location (where you do have write access),
:w <pathname> command,
and then go to a Command Prompt or PowerShell
that’s running with elevated privileges (running as Administrator)
and copy your temporary file over the target.
If you need to use the privileges of some other user
(other than Administrator),
runas to start the Command Prompt or PowerShell.