2

I sometimes open files in vim which have admin only permissions, such as config files in the program files. I edit these and attempt to save them only to discover that the file is readonly and I can't save in the original location. I have to save the file in a different place a copy it over the top.

I want to just issue a vim command to run the write as root, is this possible?

There is a unix verison here using sudo and tee What are the dark corners of Vim your mom never told you about?

Community
  • 1
  • 1
avid
  • 579
  • 5
  • 18

2 Answers2

2

The only way I know of is to open the file as admin in the first place. I know in Windows 7, you're given the option to 'Open' or 'Open as Administrator'.

I think is similar to vim in unix, such that you have to open the editor with sudo in the first place.

skeletalmonkey
  • 726
  • 1
  • 10
  • 20
  • I think I will accept this answer since it is technically correct, and maybe write a utility to save a file as admin from the vim ex mode (think I got the mode right :-}). – avid Mar 27 '11 at 08:49
  • +1, worked so simply, just by opening it via `Run As Administrator`, saved me the agony :-) – nIcE cOw Sep 21 '12 at 13:03
1

Unfortunately, the Run As Administrator does not show up in my case as seen below.

enter image description here

So I went to 'Properties' as seen in the above image and under 'Security>Edit', seen below, enabled 'Full control' to my user. Though this is not as secure as Run As Administrator. enter image description here

Stephen Jacob
  • 889
  • 1
  • 15
  • 33